Instale o ImageMagick
$ sudo apt-get install imagemagick
Salve o arquivo scale.php na pasta que deseja redimensionar as imagens
<?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);
?>
Acesse a pasta onde o arquivo scale.php foi salvo.
Execute o comando $ php scale.php 2000, onde 2000 é o tamanho máximo em pixels que cada imagem pode ter.
Fonte : http://unix.stackexchange.com/questions/38943/use-mogrify-to-resize-large-files-while-ignoring-small-ones
0 Comentários