forked from verdnatura/hedera-web
68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
|
|
require_once(__DIR__.'/image.php');
|
|
|
|
/**
|
|
* Resizes all images allocated in a directory.
|
|
*
|
|
* @param string $srcDir The source directory
|
|
* @param string $dstDir The destination directory
|
|
* @param integer $maxHeight The maximum height of resized image in pixels
|
|
* @param integer $maxWidth The maximum width of resized image in pixels
|
|
* @param boolean $rewrite Wether to rewrite the destination file if it exits
|
|
*/
|
|
class Resize extends Vn\Lib\Method {
|
|
const PARAMS = [
|
|
'srcDir'
|
|
,'dstDir'
|
|
,'maxHeight'
|
|
,'maxWidth'
|
|
,'rewrite'
|
|
,'crop'
|
|
,'symbolic'
|
|
];
|
|
|
|
function run($db) {
|
|
$options = getopt('', self::PARAMS);
|
|
|
|
$srcDir = $options['srcDir'];
|
|
$dstDir = $options['dstDir'];
|
|
$maxHeight = $options['maxHeight'];
|
|
$maxWidth = $options['maxWidth'];
|
|
$rewrite = isset($options['rewrite']);
|
|
$crop = isset($options['crop']);
|
|
$symbolic = isset($options['symbolic']);
|
|
$verbose = isset($options['verbose']);
|
|
|
|
set_time_limit(0);
|
|
|
|
$count = 0;
|
|
$dir = opendir($srcDir);
|
|
|
|
if ($dir)
|
|
while ($fileName = readdir($dir))
|
|
if (!in_array($fileName, ['.', '..'])) {
|
|
$srcFile = "$srcDir/$fileName";
|
|
$dstFile = "$dstDir/". substr($fileName, 0, -4).'.png';
|
|
|
|
if (!file_exists($dstFile) || $rewrite)
|
|
try {
|
|
$symbolicSrc = $symbolic ? $srcFile : NULL;
|
|
|
|
if ($verbose) {
|
|
echo "SRC: $srcFile\n";
|
|
echo "DST: $dstFile\n";
|
|
}
|
|
|
|
$image = Image::create($srcFile);
|
|
Image::resizeSave($image, $dstFile, $maxHeight, $maxWidth, $crop, $symbolicSrc);
|
|
imagedestroy($image);
|
|
$count++;
|
|
} catch (\Exception $e) {}
|
|
}
|
|
|
|
echo "$count files resized.\n";
|
|
}
|
|
}
|
|
|