in reply to Re: Making jpg thumbnails
in thread Making jpg thumbnails

Many thanks to CombatSquirrel for getting me on the right path. Got it to work with the following edits, just in case anybody else stumbles across this thread and wants to try it:
#!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->newFromJpeg($filename); #edited my ($width, $height) = $image->getBounds; my ($newwidth, $newheight); if (($width > 300) || ($height > 300)) { if ($width > $height) { ($newwidth, $newheight) = (150, int((150 * $height) / $width)); } else { ($newwidth, $newheight) = (int((150 * $width) / $height), 150); } } else { ($newwidth, $newheight) = ($width, $height); } my $newimg = new GD::Image($newwidth, $newheight); #edited $newimg->copyResized( $image, # source image 0, 0, # destination position 0, 0, # original position $newwidth, $newheight, $width, $height ); open (OUTFILE, ">$outfilename") or die "Failed to open '$outfilename' +for output: $!\n"; binmode(OUTFILE); #edited print OUTFILE $newimg->jpeg(100); #edited close OUTFILE;
bradcathey