PDA

View Full Version : question about create thumbnail



tester_geniusd
04-13-2006, 06:19 PM
Hello

I need create thumbnail of many formats of images. I know how do it on php with help of GD lib. But i need support many more format of files.

Please advise me solution of my problem.
Thanks.


Kind regards,
Dmitry

ilyabern
04-14-2006, 04:28 PM
Looking into this...

ASP-Hosting.ca
04-26-2006, 02:36 PM
You can do it easily on Windows with ASP.NET if that's an option for you...

mitto
08-12-2006, 04:06 AM
I dont know but what about ImageMagick and other duilt in php scripts?

danosd
08-12-2006, 10:59 AM
This is a function I used once for an image upload script. It works really well, the only thing I don't know how to do is how to preserve transparency (in gifs and pngs) when generating the thumbnail.





function createthumb($name,$filename,$new_w,$new_h){

$system=explode('.',$name);

if (preg_match('/jpg|jpeg|JPG/',$system[1])){

$src_img=imagecreatefromjpeg($name);

}

if (preg_match('/png|PNG/',$system[1])){

$src_img=imagecreatefrompng($name);

}

if (preg_match('/gif|GIF/',$system[1])){

$src_img=imagecreatefromgif($name);

}




$old_x=imageSX($src_img);

$old_y=imageSY($src_img);
If($old_x <= $new_w && $old_y <= $new_h){



$dst_img=ImageCreateTrueColor($old_x,$old_y);

imagecopyresampled($dst_img,$src_img,0,0,0,0,$old_ x,$old_y,$old_x,$old_y);
if (preg_match("/png/",$system[1]))

{

imagepng($dst_img,$filename);

}

if (preg_match("/gif/",$system[1]))

{

imagegif($dst_img,$filename);

}

else {

imagejpeg($dst_img,$filename);

}





}else {

if ($old_x > $old_y) {

$thumb_w=$new_w;

$thumb_h=$old_y*($new_h/$old_x);

}

if ($old_x < $old_y) {

$thumb_w=$old_x*($new_w/$old_y);

$thumb_h=$new_h;

}

if ($old_x == $old_y) {

$thumb_w=$new_w;

$thumb_h=$new_h;

}



$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thum b_w,$thumb_h,$old_x,$old_y);





if (preg_match("/png/",$system[1]))

{

imagepng($dst_img,$filename);

}

if (preg_match("/gif/",$system[1]))

{

imagegif($dst_img,$filename);

}

else {

imagejpeg($dst_img,$filename);

}

imagedestroy($dst_img);

imagedestroy($src_img);

}
}

GalaxySolutions
08-13-2006, 12:32 PM
Yeah, ImageMagick is your best bet