sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

The past week or so I've been going back to all the old scripts I've coded and tried to make improvements on them. I have an image gallery which originall uploaded and thumbnailed any image to 100x100 and used this in the preview for the gallery.

Because of the number of servers that have ImageMagick installed is slim, I've taken this out for the time being and doing a fake thumbnail using HTML at 100x100. (bad idea I know, but atleast people can actually import the script on their server now).

Question is, how can I calculate proportions of images so they're not all resized the same and have some get really blurred if it's a small image? All the other galleries have thumbnails of different sizes, not a preset 100x100. I need a method of resizing the thumbnails so the size doesn't distort them too much.

I'm using ImageInfo to display the image dimensions and will use HTML to create the fake thumbnails (or possibly go back to ImageMagick) if it's a must.

Thanks for your help everyone.



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Proportionally resizing of images
by valdez (Monsignor) on May 10, 2004 at 16:04 UTC

    You should use real thumbnails or you will defeat the main purpose of them! Please note that this question has been answered many times, for example: Creating thumbnails.

    Ciao, Valerio

Re: Proportionally resizing of images
by Abigail-II (Bishop) on May 10, 2004 at 16:25 UTC
    I'd use ImageMagick, or the pipeline: djpeg | pnmscale | cjpeg. I'd certainly not use the HTML method: that's the worst of two worlds: you download the full image, but only display a distorted image.

    If not having ImageMagick installed is a problem, just bundle whatever you need with your product. There are many image modifying programs available, and no doubt there's one with a license that allows you to distribute it.

    Abigail

Re: Proportionally resizing images
by Roy Johnson (Monsignor) on May 10, 2004 at 16:23 UTC
    You should create the thumbnail images yourself, not have the server do it. Ordinary resizing with -geom 100x100 in ImageMagick will constrain the images to that size bounding box, but maintain their original aspect ratio, which is what you want.

    The PerlMonk tr/// Advocate
      You can also use -geometry "100x100>" to mean, "resize to fit inside 100x100 but only if it was too large." Note the quotes on the command line to avoid shell redirection. This avoids the problem where the image was 16x16 and looks blurry when stretched.

      --
      [ e d @ h a l l e y . c c ]

      You should create the thumbnail images yourself, not have the server do it.
      I'm presuming that's a typo, and you meant "client" or "browser" where you said "server".

      When you use "dumbnails", the server downloads the full original file (thus defeating the whole point of thumbnails), and then your browser is tasked to making that big image fit inside a teeny-tiny space.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        I understood him to be suggesting that the server might generate the thumbnails while it was generating the thumbnail page. Otherwise what's the point of talking about having ImageMagick on the server?

        The PerlMonk tr/// Advocate
Re: Proportionally resizing of images
by Anonymous Monk on May 10, 2004 at 19:30 UTC

    This might sound like a lot of extra work, but in some cases it might be worth it. I once created a script with one of the popular image modules (I think it was Image::Magick but I'm not 100% positive). This script had one simple objective: grab all the images off of my digital camera (which attached to the operating system as a regular drive) and create thumbnails for them. I was extremely disappointed to see the filesize of the thumbnails generated by the module. I compared it to the filesize of a thumbnail created by using Paint Shop Pro 8 and the difference was incredible!

    So if this is for something where the thumbnails are only for images that you put up yourself, it might be worthwhile creating your own thumbnails. Of course, this is probably out of the question if you are generating thumbnails of images uploaded by users. But just a warning.

      Did you read the docs (here...) and set compression type and level for the images you were creating? On related news, I just bought a nice BMW and it sucked because when I yelled at it to turn left it did not and I ended up hitting a big old stone wall -- stupid car.


      -Waswas