I use such PHP-script, it uses ImageMagick:
<?php
$dir = ".";
$exts = array('jpg', 'jpeg', 'png', 'gif');
$max_size = is_numeric($argv[1]) ? $argv[1] : 3000;
$morgify = "mogrify -verbose -scale \"${max_size}x${max_size}>\" -quality 85";
$identify = "identify -format \"%wx%h\"";
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
$path = "$dir/$file";
// skip no images
$dot = strrpos($file, '.');
$ext = strtolower(substr($file, $dot + 1));
if (!in_array($ext, $exts)) continue;
// large size?
$size = exec("$identify \"$path\"");
list($width, $height) = explode('x', trim($size));
if (max($width, $height) > $max_size) {
// scale!
print "scale $file ${width}x${height}";
exec("$morgify \"$path\"");
print "\n";
}
}
closedir($dh);
?>
It scales all images in current directory larger than 3000 on some edge.
Run command: php scale.php OR php scale.php 2000