Ver Mensaje Individual
  #12 (permalink)  
Antiguo 05/05/2009, 02:21
moddik
 
Fecha de Ingreso: abril-2008
Ubicación: Barcelona
Mensajes: 53
Antigüedad: 16 años, 1 mes
Puntos: 2
Respuesta: En un upload, guardar tres veces una foto?

subir 3 fotos? para que subir 3 fotos si con una hay bastante usa este script, crea un archivo llamado thumbnails.php y lo enganchas:

Código PHP:
<?php
header
('Content-type: image/jpeg');
header('Content-type: image/gif');
header('Content-type: image/png');

$new_width $_GET["ancho"];
$new_height $_GET["alto"];
$ruta $_GET["ruta"];

$image "../" $ruta;

if(
preg_match("/.jpg/i""$image"))
{
    
$format 'image/jpeg';
}
if (
preg_match("/.gif/i""$image"))
{
    
$format 'image/gif';
}
if(
preg_match("/.png/i""$image"))
{
    
$format 'image/png';
}
switch(
$format)
{
    case 
'image/jpeg':
        
$fuente imagecreatefromjpeg($image);
        break;
    case 
'image/gif';
        
$fuente imagecreatefromgif($image);
        break;
    case 
'image/png':
        
$fuente imagecreatefrompng($image);
        break;
}

$imagen imagecreatetruecolor($new_width $new_height);
imagealphablending($imagenfalse);

imagecopyresampled($imagen$fuente0000$new_width$new_heightimagesx($fuente),imagesy($fuente)); // redimensiona
header("Content-type: image/jpeg");
header("Content-type: image/gif");

switch(
$format)
{
    case 
'image/jpeg':
        
imagejpeg($imagen);
        break;
    case 
'image/gif';
        
imagegif($imagen);
        break;
    case 
'image/png':
        
imagepng($imagen);
        break;
}
?>
luego pasale las fotos en el tamaño que quieras:

<img src="scripts/thumbnails.php?ruta=tufoto.jpg&ancho=85&alto=64" />

Automáticamente te ajusta el tamaño y el peso, es decir, una foto de 1024x768 de 1MB, si le dices 100x80 quizá te pese entre 20 y 50Kb sin perder resolución