Foros del Web » Programando para Internet » PHP »

Redimensionar imagenes por Upload

Estas en el tema de Redimensionar imagenes por Upload en el foro de PHP en Foros del Web. Disculpen una Vez mas.... me gustaria me ayuden con una cuestion, un moderador me aconsejo busque en este foto, y no comprendo bien... :S podrian ...
  #1 (permalink)  
Antiguo 04/08/2008, 17:12
Avatar de JoseAlejandro_Realza  
Fecha de Ingreso: agosto-2008
Ubicación: Maracay - Venezuela
Mensajes: 192
Antigüedad: 15 años, 8 meses
Puntos: 2
Redimensionar imagenes por Upload

Disculpen una Vez mas.... me gustaria me ayuden con una cuestion, un moderador me aconsejo busque en este foto, y no comprendo bien... :S podrian pasarme un codigo para redimension de imagenes al momento de subir por upload, e indicandome donde coloco los valores para que este determine el tamaño a trabajar, pues necesito que redireccione la imagen en 100x80 y 489x324..... Espero me ayuden una vez mas
  #2 (permalink)  
Antiguo 04/08/2008, 18:59
Avatar de JoseAlejandro_Realza  
Fecha de Ingreso: agosto-2008
Ubicación: Maracay - Venezuela
Mensajes: 192
Antigüedad: 15 años, 8 meses
Puntos: 2
Respuesta: Redimensionar imagenes por Upload

Bueeno... leyendo aqui y alla tengo este script pero me marca error, podrian ayudarme...?

aca tengo el o que carga el archivo que lo llamaremos cargar.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Subir archivos</title>
<link rel="STYLESHEET" type="text/css" href="estilos_admin.css">
<style type="text/css">
<!--
.style1 {
font-family: "Brush Script MT";
color: #FF0000;
font-size: 36pt;
}
body {
background-color: #006699;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body>
<h1 class="style1">Sube Tu Foto! <img src="fotos/incognita.jpg" width="126" height="109"></h1>
<br>
<form action="redimension.php" method="post" enctype="multipart/form-data">
<br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000000">
<br>
<br>
<b>Cargar Foto : </b>
<br>
<input name="userfile" type="file">
<br>
<input type="submit" value="Enviar">
</form>
</body>
</html>

aca viene el script que se encarga de montar la imagen y redimensionar:

<?php

//damos la ruta de carpeta donde guardarlo todo
$uploadDir = 'fotos/';

//damos el archivo
$file=$_FILES['Filedata']['name'];

//damos el archivo temporal (importante) es el que moveremos con move_uploaded_file
$tmp_name = $_FILES['Filedata']['tmp_name'];

//el archivio con su ruta
$uploadFile = $uploadDir . $file;

//movemos la imagen upload
move_uploaded_file($tmp_name, $uploadFile);

//sacamos la ruta de thumb quitandole el .jpg
$getUploadThumbFile = basename($uploadFile, ".jpg");

//el archivio thumb al que le incorporamos _thumb.jpg
$UploadThumbFile = $getUploadThumbFile . '_thumb.jpg';

// $imagen = imagecreatefromjpeg($tmp_name);
$imagen_thumb = imagecreatefromjpeg($uploadFile);

//aqui ponemos las opciones deseadas para la thumbnail
$anchoElegido = 100 ;
$altoElegido = 80 ;
$calidad = 50 ;

// Creamos una imagen vacia
$thumb = imagecreatetruecolor($anchoElegido,$altoElegido);

// Copiamos la thumbnail image a la imagen creada
imagecopyresampled($thumb,$imagen_thumb,0,0,0,0, $anchoElegido,$altoElegido,imagesx($imagen_thumb), imagesy($imagen_thumb));

//damos salida a la imagen thumbnail creada y copiada.
imagejpeg($thumb, $UploadThumbFile, $calidad);

?>

cuando intengo sibir las fotos me marca este Horror.!

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/enmaraca/public_html/redimension.php on line 25

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'fotos/' is not a valid JPEG file in /home/enmaraca/public_html/redimension.php on line 25

Warning: imagesx(): supplied argument is not a valid Image resource in /home/enmaraca/public_html/redimension.php on line 36

Warning: imagesy(): supplied argument is not a valid Image resource in /home/enmaraca/public_html/redimension.php on line 36

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/enmaraca/public_html/redimension.php on line 36

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'fotos_thumb.jpg' for writing: Permission denied in /home/enmaraca/public_html/redimension.php on line 39

y ya no se que hacer


http://www.enmaracay.net/cargar.php
  #3 (permalink)  
Antiguo 04/08/2008, 19:25
Avatar de chwc  
Fecha de Ingreso: julio-2008
Ubicación: Buenos Aires ! :D
Mensajes: 814
Antigüedad: 15 años, 8 meses
Puntos: 103
Respuesta: Redimensionar imagenes por Upload

fijate si tenes la carpeta fotos, y si le cambiaste los permisos a 777
  #4 (permalink)  
Antiguo 04/08/2008, 19:31
Avatar de JoseAlejandro_Realza  
Fecha de Ingreso: agosto-2008
Ubicación: Maracay - Venezuela
Mensajes: 192
Antigüedad: 15 años, 8 meses
Puntos: 2
Respuesta: Redimensionar imagenes por Upload

Si men, ya le tengo los permisos 7777 pues ya tengo otro upload trabajando con esa carpeta... y aun nada de nada
  #5 (permalink)  
Antiguo 05/08/2008, 08:02
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Redimensionar imagenes por Upload

Cita:
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/enmaraca/public_html/redimension.php on line 25
Eso te esta indicando el error la imagen que le pasaste tiene un error, o no es un archivo JPG valido.

Saludos.
  #6 (permalink)  
Antiguo 05/08/2008, 10:08
Avatar de JoseAlejandro_Realza  
Fecha de Ingreso: agosto-2008
Ubicación: Maracay - Venezuela
Mensajes: 192
Antigüedad: 15 años, 8 meses
Puntos: 2
Respuesta: Redimensionar imagenes por Upload

No men.... ya encontre el problema que tiene el scritp, y es que tengo que ejecutarlo en un mismo archivo es decir

?>
<html>

<head>
<title>web.blazonry : PHP : Upload and Resize an Image</title>

<?php

if ($_SERVER['REQUEST_METHOD'] == "POST")
{

/* SUBMITTED INFORMATION - use what you need
* temporary filename (pointer): $imgfile
* original filename : $imgfile_name
* size of uploaded file : $imgfile_size
* mime-type of uploaded file : $imgfile_type
*/

/*== upload directory where the file will be stored
relative to where script is run ==*/

$uploaddir = "fotos/fotos";


/*== get file extension (fn at bottom of script) ==*/
/*== checks to see if image file, if not do not allow upload ==*/
$pext = getFileExtension($imgfile_name);
$pext = strtolower($pext);
if (($pext != "jpg") && ($pext != "jpeg"))
{
print "<h1>ERROR</h1>Image Extension Unknown.<br>";
print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>";
print "The file you uploaded had the following extension: $pext</p>\n";


}


//-- RE-SIZING UPLOADED IMAGE

/*== only resize if the image is larger than 250 x 200 ==*/
$imgsize = GetImageSize($imgfile);

/*== check size 0=width, 1=height ==*/
if (($imgsize[0] > 250) || ($imgsize[1] > 200))
{
/*== temp image file -- use "tempnam()" to generate the temp
file name. This is done so if multiple people access the
script at once they won't ruin each other's temp file ==*/
$tmpimg = tempnam("/tmp", "MKUP");

/*== RESIZE PROCESS
1. decompress jpeg image to pnm file (a raw image type)
2. scale pnm image
3. compress pnm file to jpeg image
==*/

/*== Step 1: djpeg decompresses jpeg to pnm ==*/
system("djpeg $imgfile >$tmpimg");


/*== Steps 2&3: scale image using pnmscale and then
pipe into cjpeg to output jpeg file ==*/
system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");

/*== remove temp image ==*/
unlink($tmpimg);

}

/*== setup final file location and name ==*/
/*== change spaces to underscores in filename ==*/
$final_filename = str_replace(" ", "_", $imgfile_name);
$newfile = $uploaddir . "/$final_filename";

/*== do extra security check to prevent malicious abuse==*/
if (is_uploaded_file($imgfile))
{

/*== move file to proper directory ==*/
if (!copy($imgfile,"$newfile"))
{
/*== if an error occurs the file could not
be written, read or possibly does not exist ==*/
print "Error Uploading File.";
exit();
}
}

/*== delete the temporary uploaded file ==*/
unlink($imgfile);


print("<img src=\"$final_filename\">");

/*== DO WHATEVER ELSE YOU WANT
SUCH AS INSERT DATA INTO A DATABASE ==*/

}
?>


</head>
<body bgcolor="#FFFFFF">

<h2>Upload and Resize an Image</h2>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">

<p>Upload Image: <input type="file" name="imgfile"><br>
<font size="1">Click browse to upload a local file</font><br>
<br>
<input type="submit" value="Upload Image">
</form>

</body>
</html>

<?php
/*== FUNCTIONS ==*/

function getFileExtension($str) {

$i = strrpos($str,".");
if (!$i) { return ""; }

$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);

return $ext;

}
?>


ahora lo que no entiendo es porque si lo pongo en una carpeta para que lo suba a esa misma no lo hace, y lo lo mando a ponerla en una carpeta dentro de donde el esta, la sube, pero como con errores porque luego no abre, queda en blanco, como si se fuera borrado :S
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:36.