Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Making jpg thumbnails

by duct_tape (Hermit)
on Aug 26, 2003 at 19:54 UTC ( #286839=note: print w/replies, xml ) Need Help??


in reply to Making jpg thumbnails

Perhaps use the Imager module since you can not use Image::Magick. It doesn't look like anyone else has recommended that yet.

Here is some sample code for resizing a JPEG with Imager.

#!/usr/bin/perl -w use Imager; use strict; my $file = "something.jpg"; my $thumb_file = "something_thumb.jpg"; my $image = Imager->new() or die "Can't create Imager object"; $image->open(file => $file) or die $image->errstr; # You could also pass qtype => 'preview' to scale() to # supposedly make a smaller thumbnail (filesize wise) my $thumbnail = $image->scale(ypixels => 100) or die $image->errstr; # You could pass fd => fileno(STDOUT), instead of the file # parameter if you need to print to STDOUT. If you do so # make sure to binmode STDOUT, and disable buffering ($|++) $thumbnail->write(file => $thumb_file, type => 'jpeg') or die $thumbnail->errstr;

Also, as other people have said, if you need to generate the thumbnails on the fly, at least do some caching of them. Check if a thumbnail exists and perhaps even compare the timestamps of the thumbnail and the actual image so that you only have to generate the thumbnail when it is absolutely necessary.

When I was originally playing around with Imager I found it to be a bit slower than Image::Magick. Unfortunately I do not have any benchmarks... but it is something to keep in mind.

Hope that helps. Good luck with your application.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://286839]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2019-09-22 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (274 votes). Check out past polls.

    Notices?