in reply to Making jpg thumbnails
I hope it works and suits your needs.#!perl use strict; use warnings; use GD; my $filename = '/path/to/img/img.jpg'; my $outfilename = '/path/to/img/thumb/img.jpg'; my $image = new GD::Image $filename or die "Could not open '$filename' +: $!\n"; my ($width, $height) = $image->getBounds; my ($newwidth, $newheight); if (($width > 300) || ($height > 300)) { if ($width > $height) { ($newwidth, $newheight) = (300, int((300 * $height) / $width)); } else { ($newwidth, $newheight) = (int((300 * $width) / $height), 300); } } else { ($newwidth, $newheight) = ($width, $height); } my $newimg = $image->copyResized( $image, # source image 0, 0, # destination position 0, 0, # original position $newwidth, $newheight, $width, $height ); $newimg->(); open OUTFILE, '>', $outfilename or die "Failed to open '$outfilename' +for output: $!\n"; print OUTFILE $newimg->jpeg; close OUTFILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Making jpg thumbnails
by wirrwarr (Monk) on Aug 26, 2003 at 14:55 UTC | |
|
Re: Re: Making jpg thumbnails
by bradcathey (Prior) on Aug 30, 2003 at 14:38 UTC |