Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Perl Subroutine for resizing images
use Image::Magick;
$imagePath = "../images/";
@sizes = ("480", "768", "992", "1200");
#reading sub, takes argument (filename)
sub resizeFiles {
@fileList = @_;
foreach (@fileList) {
print "Reading $_\n";
my $p = new Image::Magick;
my $filename = $_;
foreach (@sizes) {
my $new = $p->Clone;
(my $without_extension = $filename) =~ s/\.[^.]+$//;
$new_filename = $without_extension."-".$_.".jpg";
$new->Write(filename => $new_filename, interlace=> plane, quality => 85);
#make @2X for retina
$retina_filename = $without_extension."-".$_."\@2X.jpg";
$new->Write(filename => $retina_filename, interlace=> plane, quality => 85);
chdir($imagePath) or die "Can't chdir to $imagePath";
#run the resizeFiles sub in a loop for maximum effiency. panorama.jpg was just my demo file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.