Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created March 6, 2013 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/5098910 to your computer and use it in GitHub Desktop.
Save tluyben/5098910 to your computer and use it in GitHub Desktop.
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