Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Resize all images in a directory. Images should be of the format xxx_WIDTHxHEIGHT.ext, so bla_2048x1536.png, run as : ./cut50.pl 2048 1536 and all images are resized to 1024x768.
#!/usr/bin/perl
$x = $ARGV[0];
$y = $ARGV[1];
if (not $x or not $y) {
print "./cut50.pl width height\n";
exit;
}
$fv = "_$x"."x"."$y"."\\.";
$nx = int($x / 2);
$ny = int($y / 2);
foreach(glob("*.*")) {
chomp;
$f = $_;
next if not /$fv/;
/^(.*?)$fv(.*)$/;
$nn = $1."_".$nx."x".$ny.".".$2;
print `convert "$f" -resize 50% "$nn"`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment