Might I suggest using CGI.pm's method for this? # png good, gif bad
print img({-src => 'http://myserver/image.png',
-width => '500',
-height => '60',
-alt => 'My Image',
-title => 'This is my image',
});
It will produce much more readable code, both in your script and in the browser, and you don't have to worry about escaping characters as rigidly as you do with "raw" print() statements.
There's also the resize()/convert() options of Image::Magick, which can do things like: use strict;
use Image::Magick;
my $image = Image::Magick->new();
$x = $image->Read(filename =>'image.png');
$x = $image->Resize(geometry =>'640x480');
$x = $image->Write(filename =>'image-th.png',
quality =>75);
@$image = ();
Lastly, there's HTMLThumbnail, by Benjamin Franz.
Resizing the images sent to the user by sending them the entire "full-size" image, and forcing the browser to resize it as a thumbnail is bad for several reasons: -
You're relying on the browser to "properly" render and quantize the image as a smaller or larger reproduction of the original, which may not look like you want it to.
- If the user hits a page of 50 thumbnails, all full-size images, scaled down to 100x100 pixels, and only ever looks at some of them, he has to still download all of them into his local cache, full-size, before he can view any of them. Don't burdon your users with unnecessary bandwidth that can be better used to serve content to them.
- Forcing full-size images down the pipe to the user slows their browsing experience, and the speed with which your page draws in their browser.
In short, don't, especially when there are better alternatives. |