streams/Code/Daemon/CacheThumb.php
Mike Macgirvin 0c1a256139 more cleanup
2022-08-21 17:36:09 +10:00

50 lines
1.4 KiB
PHP

<?php
/** @file */
namespace Code\Daemon;
require_once('include/photos.php');
class CacheThumb
{
public static function run($argc, $argv)
{
if ($argc != 2) {
return;
}
$path = 'cache/img/' . substr($argv[1], 0, 2) . '/' . $argv[1];
$imagesize = getimagesize($path);
if (! $imagesize) {
return;
}
$width = $imagesize[0];
$height = $imagesize[1];
$max_thumb = get_config('system', 'max_cache_thumbnail', 1024);
if ($width > $max_thumb || $height > $max_thumb) {
$imagick_path = get_config('system', 'imagick_convert_path');
if ($imagick_path && @file_exists($imagick_path)) {
$tmp_name = $path . '-001';
$newsize = photo_calculate_scale(array_merge($imagesize, ['max' => $max_thumb]));
$cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $path) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name);
for ($x = 0; $x < 4; $x++) {
exec($cmd);
if (file_exists($tmp_name)) {
break;
}
}
if (! file_exists($tmp_name)) {
return;
}
@rename($tmp_name, $path);
}
}
}
}