streams/Code/Daemon/CacheThumb.php

33 lines
802 B
PHP
Raw Normal View History

2021-12-03 03:01:39 +00:00
<?php
/** @file */
2022-02-16 04:08:28 +00:00
namespace Code\Daemon;
use Code\Lib\Resizer;
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);
$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
}
}
}