Foros del Web » Programando para Internet » PHP »

Consulta sobre generacion de thumbnail

Estas en el tema de Consulta sobre generacion de thumbnail en el foro de PHP en Foros del Web. Hola: Estoy buscando la manera de poder generar una imagen thumbnail de buena calidad y poco peso. Que recomiendan usar, he probado con GD y ...
  #1 (permalink)  
Antiguo 30/10/2012, 12:34
 
Fecha de Ingreso: octubre-2012
Ubicación: Lima
Mensajes: 3
Antigüedad: 14 años, 1 mes
Puntos: 0
Pregunta Consulta sobre generacion de thumbnail

Hola:

Estoy buscando la manera de poder generar una imagen thumbnail de buena calidad y poco peso.

Que recomiendan usar, he probado con GD y con ImageMagick pero no logro obtener buenos resultados

esta es la imagen png[URL="http://imgur.com/BRBCu"]http://imgur.com/BRBCu[/URL]
y la he querido generar en 157x115 en jpg

con estas funciones
esta en GD
Código PHP:
function createThumbnail($img, $imgPath, $suffix, $newWidth, $newHeight, $quality, $to = 'jpg')
{
  
// Open the original image.
  //$original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original");
  
$original = imagecreatefrompng("$imgPath/$img") or die("Error Opening original");
  list(
$width, $height, $type, $attr) = getimagesize("$imgPath/$img");
 
  
// Resample the image.
  
$tempImg = imagecreatetruecolor($newWidth, $newHeight) or die("Cant create temp image");
  
//imagecopyresized($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height) or die("Cant resize copy");
  
imagecopyresampled($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height) or die("Cant resize copy");
 
  
// Create the new file name.
  
$newNameE = explode(".", $img);
  
//$newName = ''. $newNameE[0] .''. $suffix .'.'. $newNameE[1] .'';
  
$newName = ''. $newNameE[0] .''. $suffix .'.'. $to .'';
 
  
// Save the image.
  
if($to == 'jpg'){
    
imagejpeg($tempImg, "$imgPath/$newName", $quality) or die("Cant save image");
  }
  if(
$to == 'png'){
    
//echo ceil( $quality / 10 );
    
if($quality < 100){
        
imagepng($tempImg, "$imgPath/$newName" , ceil( $quality / 10 )) or die("Cant save image");
    }else{
        
imagepng($tempImg, "$imgPath/$newName" ) or die("Cant save image");
    }
  }
 
  
// Clean up.
  
imagedestroy($original);
  
imagedestroy($tempImg);
  return 
true;
} 
y esta en Imagick
Código PHP:
function createThumbIMK($img, $imgPath, $thumbDir, $suffix, $newWidth, $newHeight, $to = 'jpg' , $quality = '100',$optimize = false) {
  
// add in the suffix after the '.' dot.
    
$newNameE = explode(".", $img);
    
$newName = ''. $newNameE[0] .''. $suffix .'.'. $to .'';
 
  
// ImageMagicK doesnt like '/' and 'x' characters in the command line call.
    
$uploadedImg = ''. $imgPath .'/'. $img .'';
    
$newThumb = ''. $thumbDir .'/'. $newName .'';
    
$newRes = ''. $newWidth .'x'. $newHeight .'';
 

    
$ct = system("/usr/bin/convert -strip -quality $quality%  -resize $newRes $uploadedImg $newThumb", $retval);
    
    
        
    if(
$to == 'jpg' && $optimize){
        
$ct = exec("c:\jpegoptim\jpegoptim.exe -p -t -f --strip-all $newThumb", $retval);
        
//$ct = exec("/jpegoptim -p -t -f --strip-all $newThumb", $retval);
        //echo $ct.'<br>';
    
}
    if(
$to == 'png' && $optimize){        
        
$ct = exec("/usr/bin/optipng $newThumb", $retval);
    }
    return 
$ct;
} 
Pero no logro tener buenos resultados si bajo a menos de 97% de calidad, a menos de eso empiezan a verse pixelaciones, aunque si el peso de la imagen es menor.

En cambio en photoshop, con la opcion "guardar para la web" a 80% las imagenes en jpg y 157x115 se ven muy bien.

Agradezco cualquier tipo de informacion

Saludos.
  #2 (permalink)  
Antiguo 30/10/2012, 12:59
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 15 años, 9 meses
Puntos: 288
Respuesta: Consulta sobre generacion de thumbnail

y por que no validas el peso y en base a eso reducis la calidad de la imagen,
por ejemplo una imagen de 1mb si se la reduce a un cuarto de mb se seguira viendo bien,
pero no sirve para una imagen pequeña

Etiquetas: imagenes, thumbnails
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 16:30.