Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

creating thumbnails

by Anonymous Monk
on Jan 03, 2002 at 07:04 UTC ( [id://135902]=perlquestion: print w/replies, xml ) Need Help??

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

I've got a perl script to upload images from the web-- which is working fine. But when someone uploads the image, I want to make a thumbnail image copy at the same time. I'm not even sure where to begin with this. It has to be fully automated, I've got too many people uploading images to look at each one, but I'm not too conceaerned with the image quality (within reason). As long as the image is recognizable, it'll work.

Any ideas?

Ashley

Replies are listed 'Best First'.
(ar0n) Re: creating thumbnails
by ar0n (Priest) on Jan 03, 2002 at 07:13 UTC
    This is from a small test script I wrote yesterday. It creates a thumbnail while retaining image proportions.
    #!/usr/bin/perl -w use strict; use Image::Magick; sub make_thumb { my $file = shift; my $thumb = shift; my $size = 100; # image size; either width or height will be a 100 + pixels (or both) my $img = new Image::Magick; $img->Read($file); my ($width, $height) = $img->Get("width", "height"); if ($width > $height) { my $ratio = $size / $width; $height *= $ratio; $width = $size; } elsif ($height > $width) { my $ratio = $size / $height; $width *= $ratio; $height = $size; } else { $width = $size; $height = $size; } $img->Resize( width => $width, height => $height, blur => 1 ); $img->Write($thumb); } make_thumb("/path/to/img.png", "/path/to/thumbnail.png");
Re: creating thumbnails
by impossiblerobot (Deacon) on Jan 03, 2002 at 08:05 UTC
Re: creating thumbnails
by AidanLee (Chaplain) on Jan 03, 2002 at 07:09 UTC
    There are a couple of popular graphics libraries with Perl interfaces. GD is one and Image::Magick is another. They're both fairly well documented.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://135902]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found