use strict; use warnings; use Imager; processPics("./images"); sub processPics { my $dir = shift; my $newDat = ''; # build list of jpg files to process opendir my $dh, $dir or die "Could not open '$dir' for reading '$!'\n"; my @pics = grep(/\.jpg$/, readdir $dh); closedir $dh; # check for subdirs and make if missing mkdir "${dir}/medium" unless (-d "${dir}/medium"); mkdir "${dir}/thumbs" unless (-d "${dir}/thumbs"); mkdir "${dir}/upright" unless (-d "${dir}/upright"); # process image dir for my $p (@pics) { my $img = Imager->new(file=>"${dir}/${p}", type=>'jpeg') or die Imager->errstr(); my $med = $img->copy(); my $thumb = $img->copy(); my $rot90; # sets width to 750px, write out image $med = $img->scale(xpixels=>750); $med->write(file=>"${dir}/medium/${p}") or die $med->errstr; # sets the height to 150px, write out image $thumb = $img->scale(ypixels=>150); $thumb->write(file=>"${dir}/thumbs/${p}") or die $thumb->errstr; # rotate image, write out image $rot90 = $img->rotate(degrees=>-90); $rot90->write(file=>"${dir}/upright/${p}") or die $rot90->errstr; # append filename without the extension $newDat .= (split(/\./, $p))[0] . '|'; } # display $newDat after removing trailing | chop $newDat if $newDat; print "completed: ${newDat}\n"; }