...

View Full Version : Is there any Thumbnail Class in PHP



eshban
07-12-2005, 02:23 PM
Hi, i am working on my shopping cart. Is there any class in PHP, which supports Thumbnails. Like I want to upload two images of every product. One image is thumbnail (for quick access) and other is a high quality image(use for closer look).

plz reply me about that class or function and how to use it.

Regards,
Eshban

delinear
07-12-2005, 03:01 PM
PHP has lots of image handling functions (http://uk2.php.net/manual/en/ref.image.php) which will allow you to manipulate images exactly the way you want.

What you need will depend upon exactly how you want to implement this, for instance you might want to physically create two separate files (the full sized picture and the thumbnail) and store them both on your fileserver, or you might want to dynamically generate and show the thumbnails on the fly, which will cut down on the space required on the server but uses more resources to generate the images each time.

Look for some PHP GD tutorials and you will find loads of examples :thumbsup:

missing-score
07-12-2005, 03:56 PM
Personally, I would reccomend saving the files rather than dynamically generating them. If you are expecting very few visitors then I guess generating them is ok, but I would probably still go with saving the files. Thumbnails arent that big.

Something really basic might look like:




$image = 'filename_of_large_image.png';
$thumbnail_width = 100;
$thumbnail_height = 80;

$oldim = imagecreatefrompng($image);
$old_width = imagesx($oldim);
$old_height = imagesy($oldim);

$im = imagecreatetruecolor($thumbnail_width, $thumbnail_height);

imagecopyresampled($im, $oldim, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $old_width, $old_height);

imagepng($im);
imagedestroy($im, 'newfilename.png');

delinear
07-12-2005, 04:29 PM
Personally, I would reccomend saving the files rather than dynamically generating them. If you are expecting very few visitors then I guess generating them is ok, but I would probably still go with saving the files. Thumbnails arent that big.
[/php]
I totally agree, although in some instances I don't mind generating them each time, for instance in the administrative area of a site I just worked on I display thumbnails of images that are displayed on the main site in two sizes already (a larger thumbnail and full size). Rather than have three files saved for every image, and since I know the admin area will be accessed very rarely, I decided what the heck, just create them on the fly. But generally speaking, yes, in most instances it makes more sense to save them to the file system, definitely.

missing-score
07-12-2005, 04:43 PM
I totally agree, although in some instances I don't mind generating them each time, for instance in the administrative area of a site I just worked on I display thumbnails of images that are displayed on the main site in two sizes already (a larger thumbnail and full size). Rather than have three files saved for every image, and since I know the admin area will be accessed very rarely, I decided what the heck, just create them on the fly. But generally speaking, yes, in most instances it makes more sense to save them to the file system, definitely.
Yeah, thats a situation where I would generate the images on the fly :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum