Thumbnails
| From: | Jonathan Lara | Date: | Tue, 09 Sep 2003 23:21:51 +0000 |
| Subject: | Thumbnails | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-40236@lists.php.net to get a copy of this message | ||
Hola listeros, mi pregunta/solicitud es la siguiente:
He usado varias funciones para la creacion de thumbails, sin embargo cuando
involucra tratamiento de colores quedan muy probres las imagenes generadas,
he acudido a google usando muchos tipos diferentes sin embargo aun no
encuentro alguna que realmente me satisfaga, y me pregntaba si alguno de uds
tenia alguna que les funcionara bien, ideal seria si usara gd < 2 pero igual
acepto cualquier aporte, obviamente lo esencial es que sea portable
(win/*nix) ya que desarrollo en ambas plataformas, gracias
y adjunto el que actualmente estoy utilizando
function thumbnail ($image_path,$thumb_path,$image_name,$thumb_width,
$pref)
{
$extget = strtolower(substr( strrchr($image_name, "."), 1));
if ($extget == "jpg" || $extget == "jpeg"){ $src_img =
imagecreatefromjpeg("$image_path/$image_name"); $ext= ".jpg"; }
if ($extget == "gif"){ $src_img =
ImageCreateFromGif("$image_path/$image_name"); $ext= ".gif"; } // no funkara
if ($extget == "png"){ $src_img =
imagecreatefrompng("$image_path/$image_name"); $ext= ".png"; }
$origw = imagesx($src_img);
$origh = imagesy($src_img);
$new_w = $thumb_width;
$diff = $origw/$new_w;
$new_h = $new_w;
$dst_img = imagecreate($new_w,$new_h);
for($a=0;$a<imagecolorstotal ($src_img);$a++)
{
$color = ImageColorsForIndex($src_img,$i);
$R=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 *
($color['blue']);
$G=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 *
($color['blue']);
$B=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 *
($color['blue']);
ImageColorSet($src_img, $a, $R, $G, $B);
}
$image_name = eregi_replace(".$extget", "", $image_name);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),i
magesy($src_img));
imagejpeg($dst_img, "$thumb_path/$pref"."$image_name".".jpg");
return true;
}