Created
March 26, 2014 19:11
-
-
Save geetotes/9790951 to your computer and use it in GitHub Desktop.
Perl Subroutine for resizing images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
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 = $_; | |
$p->Read($filename); | |
foreach (@sizes) { | |
my $new = $p->Clone; | |
$new->Resize(geometry=>$_); | |
(my $without_extension = $filename) =~ s/\.[^.]+$//; | |
$new_filename = $without_extension."-".$_.".jpg"; | |
$new->Write(filename => $new_filename, interlace=> plane, quality => 85); | |
#make @2X for retina | |
$new->Resize(geometry=>$_*2); | |
$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 | |
resizeFiles("panorama.jpg"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment