Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lahore, Pakistan
    Posts
    150
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Is there any Thumbnail Class in PHP

    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

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP has lots of image handling functions 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

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:

    $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$oldim0000$thumbnail_width$thumbnail_height$old_width$old_height);

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

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by missing-score
    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.

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by delinear
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •