Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/06/2007, 03:52
xias
 
Fecha de Ingreso: enero-2002
Mensajes: 838
Antigüedad: 24 años, 10 meses
Puntos: 1
problema con creacion de thumbnails de un gif

hola:

estoy generando thumbnails para mostrar imagenes mas pequeñas en mi pagina web.

Todo funciona bien hasta que es un gif...

¿Qué estoy haciendo mal????

Gracias, un saludo

este es mi codigo:

inicio.php

Código PHP:
<img src="imagen.php?id=<?php echo $id_prod[$i];?>" border="1">
donde $id_prod[$i] es el resultado de una consulta de la que obtengo las ids de las imagenes

imagen.php
Código PHP:
ob_start();

function 
imagecreatefromfile($imagefile)
{
    
$resultado = false;
    
    
$dot = (strlen($imagefile) - strrpos($imagefile, ".")-1)*(-1);

    
$ext = substr($imagefile, $dot);
    
$ext = strtolower($ext);    
        
    if( 
$ext == "gif") {
        if (
$src_img = imagecreatefromgif($imagefile)) {
            
$resultado = $src_img;
        }
    } else if( 
$ext == "jpg" || $ext == "jpeg") {
        if (
$src_img = imagecreatefromjpeg($imagefile)) {
            
$resultado = $src_img;
        }
    } else if( 
$ext == "png") {
        if (
$src_img = imagecreatefrompng($imagefile)) {
            
$resultado = $src_img;
        }
    } else if( 
$ext == "jpg" || $ext == "jpeg") {
        if (
$src_img = imagecreatefromjpeg($imagefile)) {
            
$resultado = $src_img;
        }
     }
    
    return 
$resultado;            
}

function 
generate_thumbnail($imagefile, $ancho, $calidad = 100)
{
    if( (
$src_img = imagecreatefromfile($imagefile)) == false )
    {
        exit;
    }
    else
    {
        
$hw = getimagesize($imagefile);
        
        
$new_w = $ancho;
        
        
$new_h = $hw["0"]/($hw["1"]/$ancho);
    
        
$dst_img = @imagecreatetruecolor($new_h, $new_w);
        if(!
$dst_img) {
          
$dst_img = imageCreate($new_h, $new_w);
        }
        
        
imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_h,$new_w,imagesx($src_img),imagesy($src_img));
        
imagejpeg($dst_img,"", $calidad);
        
ImageDestroy($src_img);
        
ImageDestroy($dst_img); 
    }
}
....
conexion a bd
....
$reg = mysql_query("SELECT foto FROM productos WHERE codigo_producto = ".$_GET['id']."")or die(mysql_error());
$row = mysql_fetch_array($reg);
$file=$row['foto'];
header("Content-type: image/".$ext."");
$imagen=generate_thumbnail($file, 50);
echo 
$imagen;
?> 
__________________
Muchas gracias, saludos.