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

In reply to Re: Re: Making jpg thumbnails by bradcathey
in thread Making jpg thumbnails by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.