2021-12-03 03:01:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @file */
|
2020-03-11 22:22:34 +00:00
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
namespace Code\Daemon;
|
2022-09-11 07:35:47 +00:00
|
|
|
use Code\Lib\Resizer;
|
2020-03-11 22:22:34 +00:00
|
|
|
|
|
|
|
require_once('include/photos.php');
|
|
|
|
|
2022-11-27 09:15:28 +00:00
|
|
|
class CacheThumb implements DaemonInterface
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2022-11-27 09:15:28 +00:00
|
|
|
public function run(int $argc, array $argv): void
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2022-08-21 07:36:09 +00:00
|
|
|
if ($argc != 2) {
|
2021-12-03 03:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = 'cache/img/' . substr($argv[1], 0, 2) . '/' . $argv[1];
|
2022-08-21 07:36:09 +00:00
|
|
|
$imagesize = getimagesize($path);
|
2021-12-03 03:01:39 +00:00
|
|
|
|
2022-08-21 07:36:09 +00:00
|
|
|
if (! $imagesize) {
|
2021-12-03 03:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$max_thumb = get_config('system', 'max_cache_thumbnail', 1024);
|
2022-10-20 20:00:55 +00:00
|
|
|
$resizer = new Resizer(get_config('system','imagick_convert_path'), $imagesize);
|
2022-09-11 07:35:47 +00:00
|
|
|
$resized = $resizer->resize(PROJECT_BASE . '/' . $path, PROJECT_BASE . '/' . $path . '-001', $max_thumb);
|
|
|
|
if ($resized) {
|
|
|
|
@rename($path . '-001', $path);
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|