52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
$maxThumbDimension = 50;
|
|
|
|
$dir = $argv[1];
|
|
$imagedir = "files/$dir/product_images";
|
|
echo("$imagedir\n");
|
|
|
|
$files = array();
|
|
if (is_dir($imagedir)) {
|
|
$dir = opendir($imagedir);
|
|
while (($file = readdir($dir)) != false) {
|
|
if ($file == ".") continue;
|
|
if ($file == "..") continue;
|
|
if (preg_match("/-tn\./",$file)) continue;
|
|
$files[] = $file;
|
|
}
|
|
}
|
|
|
|
$cmd="/usr/bin/convert";
|
|
|
|
for ($i = 0; $i < count($files); $i++) {
|
|
$image = $files[$i];
|
|
|
|
list($name,$ext) = explode('.',$image);
|
|
$thumbnail = $name."-tn.".$ext;
|
|
echo("$thumbnail\n");
|
|
|
|
// Get image dimensions
|
|
$image_size = GetImageSize("$imagedir/$image");
|
|
$image_width = $image_size[0];
|
|
$image_height = $image_size[1];
|
|
|
|
$target = "$imagedir/temp";
|
|
|
|
if ($image_width >= $image_height) {
|
|
// Create the thumbnail
|
|
$height = intval($image_height * $maxThumbDimension / $image_width);
|
|
$command = "$cmd -size {$image_width}x$image_height $imagedir/$image -resize {$maxThumbDimension}x$height +profile \"*\" $target";
|
|
exec($command);
|
|
rename($target,"$imagedir/$thumbnail");
|
|
}
|
|
else {
|
|
// Create the thumbnail
|
|
$width = intval($image_width * $maxThumbDimension / $image_height);
|
|
$command = "$cmd -size {$image_width}x{$image_height} $imagedir/$image -resize {$width}x{$maxThumbDimension} +profile \"*\" $target";
|
|
exec($command);
|
|
rename($target,"$imagedir/$thumbnail");
|
|
}
|
|
}
|
|
|
|
?>
|