Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/03/2006, 04:29
perrogrun
Invitado
 
Mensajes: n/a
Puntos:
Thumbnail on the fly ( jpeg y gif )

Hola amigos, bueno lo primero que tengo que deciros es que yo vengo del lado oscuro de la programación web osea del asp y ahora estoy metiendome con el php a tope, estaba buscando un thumnail que tengo hecho en asp que hace las imágenes pequeñas en memoria y las muestra, he encontrado varios thumbnail en php pero lo que hacen es copiar la imagen reducida en otro fichero en el servidor remonbrado. Pero ya os digo, yo lo que quería es que no se guarde la imagen pequeña en es server sino que se creen en memoria y la muestre. Encontré un código para jpeg, pero con gif no funcionaba, por lo que trasteando un poco ya lo he solucionado. Os dejo aquí el codigo por si a alguien le hace falta:

Página resize.php
Código PHP:
<?php 
// Useage: thumbnail.php?im=image.jpg
// Optional: thumbnail.php?im=image.jpg&amp;maxsize=100
$im      $_GET['im'];
$maxsize $_GET['maxsize'];
if (
strpos($im,"gif")==false){


            
if (
$maxsize == '') {
    
$maxsize 100;
}

// The file
$filename $im;

// Set a maximum height and width
$width  $maxsize;
$height $maxsize;

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width_orig$height_orig) = getimagesize($filename);

if (
$width && ($width_orig $height_orig)) {
    
$width = ($height $height_orig) * $width_orig;
} else {
    
$height = ($width $width_orig) * $height_orig;
}

// Resample
$image_p imagecreatetruecolor($width$height);
$image   imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);

// Output
imagejpeg($image_p);
imagedestroy($image);
imageDestroy($image_p);

}
//------------------------------------------------------------------   gif
else
{




            
if (
$maxsize == '') {
    
$maxsize 100;
}

// The file
$filename $im;

// Set a maximum height and width
$width  $maxsize;
$height $maxsize;

// Content type
  
Header("Content-type: image/gif"); 

// Get new dimensions
list($width_orig$height_orig) = getimagesize($filename);

if (
$width && ($width_orig $height_orig)) {
    
$width = ($height $height_orig) * $width_orig;
} else {
    
$height = ($width $width_orig) * $height_orig;
}

// Resample
$image_p imagecreatetruecolor($width$height);
$image   imagecreatefromgif($filename);
imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);

// Output
 
imageGif($image_p);
imagedestroy($image);
imageDestroy($image_p);
$fuente = @imagecreatefromgif($im);
           
    
       
}
?>
Y ahora simplemente para llamarla:

Código:
<img src="resize.php?im=images/vehiculo34/05.jpg&maxsize=188">
Bueno no se si a alguien le servirá pero aki os la dejo, la verdad es que no he probado con png, seguiro que hay cientos de scripts como este pero bueno, yo dejo aki mi aportación.

Chau y que la fuerza os acompañe!!! jejej