Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2002
    Location
    chica go go
    Posts
    11,858

    Most efficient thumbnailing method?

    I'm considering a thumbnailing measure for my image hosting service, and was wondering what you programming forum people feel is the most efficient method of generating thumbnails.

    Right now, I'm looking at a simple little imagemagick command:

    Code:
    convert upload.jpg -thumbnail 300 -fill darkblue -pointsize 15 -draw "text 200,210 'photos.cx'" upload-t.jpg
    However, I can't help to think that there might be a method out there.

    Features i'd like to have:

    1) Resize based on aspect ratio, 300 pixels on the longest side
    2) ability to embed some text, or possibly a logo in the bottom right corner
    3) Optionally, the ability to change opacity in the source image, but leave embedded logo opacity at 100%

  2. #2
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    The way I scale and keep aspect ratio is to take the size I want for the longest side and divide that by the longest side of the image, that is then the scale. I then multiply the scale by each dimention.. some code might make it easier to explain.
    Code:
    $scale = ($in{size} / $height) if ($height > $width);
    $scale = ($in{size} / $width) if ($width > $height);
    $scale = ($in{size} / $width) if ($width == $height);
    
    $tn = GD::Image->new(($width * $scale), ($height * $scale)) or die "Can't make image\n";
    $tn->saveAlpha(1);
    $tn->copyResized($image,0,0,0,0,($width * $scale), ($height * $scale),$width,$height);
    This code uses GD in Perl btw. It has functions to insert logos and mess with opacity etc.

  3. #3
    Here is image resize using PHP:
    PHP Code:
    $max_thumbnail_size 200;
    $thmb_height = ($width $height) ? ($height $width) * $max_thumbnail_size $max_thumbnail_size;
    $thmb_width = ($width $height) ? $max_thumbnail_size : ($width $height) * $max_thumbnail_size;

    $thmb imagecreate($thmb_width$thmb_height);
    $gdpic_in imagecreatefromjpeg($pic_file);
    imagecopyresized($thmb$gdpic_in0000$thmb_width$thmb_height$width$height); 
    I'm not sure you need exaclty PHP, so there is another image resize methods, so find your favorite.
    Last edited by astellar; 10-23-2006 at 08:17 PM.

  4. #4
    Join Date
    Feb 2006
    Location
    Buffalo NY
    Posts
    1,348
    I would either use GD (with PHP personally) and either resize as the above post suggests, or just when you output the html just change the height / width.

    (<img src="blah.jpg" width="250" height="250" /> etc)
    Cody R.
    Hawk Host Inc. Proudly Serving websites since 2004.
    Let's Encrypt Sponsor.

  5. #5
    Join Date
    Aug 2001
    Location
    Central USA
    Posts
    200
    I would go with GD since there are far more examples out there and it's much easier to find code for. You will want to create some sort of resize cache on your hard disk to save the thumbnail images so you're not regenerating them on the fly every time they are requested. Hard disk space is far cheaper than processing power. This method also has the advantage of the images getting cached on the user's computer so they are not downloaded each time either, saving you bandwidth.
    InvoiceMore - Online Billing & Invoicing
    phpDataMapper - Object-Oriented PHP5 Data Mapper ORM

  6. #6
    Join Date
    Feb 2006
    Location
    Buffalo NY
    Posts
    1,348
    I agree with the above statement. What I usually do is just save them using imagejpeg() to the "thumbs" directory, and the full image to "images" with the same filename. This way it's easy to link / etc.
    Cody R.
    Hawk Host Inc. Proudly Serving websites since 2004.
    Let's Encrypt Sponsor.

Posting Permissions

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