Foros del Web » Programando para Internet » PHP »

muy buen script (upload y resize)

Estas en el tema de muy buen script (upload y resize) en el foro de PHP en Foros del Web. Hola a todos he encontrado este script que es un lujo Hace justamente eso 1-Sube un archivo 2-lo achica hace una copia de la version ...
  #1 (permalink)  
Antiguo 10/05/2007, 07:53
 
Fecha de Ingreso: diciembre-2005
Ubicación: Barcelona
Mensajes: 1.428
Antigüedad: 18 años, 4 meses
Puntos: 15
muy buen script (upload y resize)

Hola a todos
he encontrado este script que es un lujo

Hace justamente eso

1-Sube un archivo
2-lo achica hace una copia de la version mas pequena
3-luego muestra un imagen pequena que es un link a la imagen original.

El unico defecto es que solo acepta imagenes jpg y no gif.

codigo

<body>
<?php

if(isset($_POST['Submit']))
{
$size = 150; // the thumbnail height
$filedir = 'uploads/'; // the directory for the original image
$thumbdir = 'uploads/'; // the directory for the thumbnail image
$prefix = 'small_'; // the prefix to be added to the original name
$maxfile = '2000000';
$mode = '0666';
$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];
if (isset($_FILES['image']['name']))
{
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_heig ht)
or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img)
or die('Problem In opening Source Image');
if(function_exists('imagecopyresampled'))
{
imagecopyresampled($destimg,$srcimg,0,0,0,0,
$new_width,$new_height,ImageSX($srcimg),ImageSY($s rcimg))
or die('Problem In resizing');
}else{
Imagecopyresized($destimg,$srcimg,0,0,0,0,
$new_width,$new_height,ImageSX($srcimg),ImageSY($s rcimg))
or die('Problem In resizing');
}
ImageJPEG($destimg,$prod_img_thumb,90)
or die('Problem In saving');
imagedestroy($destimg);
}
echo '
<a href="'.$prod_img.'">
<img src="'.$prod_img_thumb.'" width="'.$new_width.'"
heigt="'.$new_height.'">
</a>';
}else{
echo '
<form method="POST" action="'.$_SERVER['PHP_SELF'].'"
enctype="multipart/form-data">
<input type="file" name="image"><p>
<input type="Submit" name="Submit" value="Submit">
</form>';
}
?>

</body>
</html>
  #2 (permalink)  
Antiguo 10/05/2007, 07:56
Avatar de el cirujano  
Fecha de Ingreso: mayo-2003
Ubicación: Frente al PC
Mensajes: 609
Antigüedad: 20 años, 11 meses
Puntos: 3
Re: muy buen script (upload y resize)

Busca en el foro unos temas por THUMBS... dentro de uno de ellos, no recuerdo su titulo ahorita, se usa un SWITCH para que se detecte si la imagen es JPG, GIF, PNG... y lo incluyes en este apartado...

Código PHP:
$destimg=ImageCreateTrueColor($new_width,$new_height)
or die(
'Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img)
or die(
'Problem In opening Source Image');
if(
function_exists('imagecopyresampled')) 
__________________
CSS2 + AJAX + PHP + MySQL, una mezcla sin competencia!!!!!!
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 19:39.