I found using Imager and Imager::File::JPEG the easiest solution. Works on Ubuntu, and I assume other Linux flavors, not on Windows

here's a simple script that iterates the .jpg files in a directory and resizes them.

use strict; use warnings; use Imager; use Imager::File::JPEG; my $folder = shift; my $dir = "/media/mark/My Passport/archive"; #starting point $dir = $dir . '/'. $folder; #target subdirectory chdir($dir); my $dh; opendir($dh, $dir); while(readdir($dh)){ my $fn = $_; next unless $fn=~ m/\.jpg$/; my $newimg; print "checking $fn\n"; my $img=Imager->new(file=>$fn,type=>'jpeg'); my ($height, $width); $height = $img->getheight; $width = $img->getwidth; my $orient = 'Portrait'; #default if ($height < $width){ $orient = 'Landscape'; } print "processing $fn height->$height width=$width orient = $orien +t\n"; if($orient eq 'Portrait' && $height < 800){ $newimg = $img->scale(ypixels=>900); } elsif($orient eq 'Landscape' && $width < 1200){ next if ($height / $width) >= 0.75; $newimg = $img->scale(xpixels=>1200); } else{ #dimensions OK, nothing to do next; } $height = $newimg->getheight; $width = $newimg->getwidth; print "saving $fn orientation->$orient, width->$width height->$hei +ght\n"; $newimg->write(file=>$fn, type=>'jpeg',jpegquality=>100) or die "cannot save altered image $img->errstr"; + }

In reply to Re: resize image by sindicalista
in thread resize image by esolm

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.