bradcathey#!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;
In reply to Re: Re: Making jpg thumbnails
by bradcathey
in thread Making jpg thumbnails
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |