Add optional images to slides
Slides (except YouTube) can carry one image. Uploads are validated, rotated by EXIF orientation, scaled to 1600 px and stored as WebP outside webroot, which also strips camera metadata. Images have an alt text (or are marked decorative) and a layout: top, side or full screen (content slides). Files are removed after the commit when a slide is deleted or its image is replaced, with the poll, and `bin/cake images_cleanup` sweeps leftovers. Duplicated slides get their own file. Docker image gains gd with WebP. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c7818ee40
commit
a395b50894
30 files changed
+1705
-11
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\ImageService;
|
||||
use Cake\Command\Command;
|
||||
use Cake\Console\Arguments;
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\Console\ConsoleOptionParser;
|
||||
|
||||
/**
|
||||
* Removes image files that no slide refers to any more (aborted uploads, crashes while deleting).
|
||||
* Idempotent, safe to run at any time, e.g. from cron.
|
||||
*
|
||||
* Usage: bin/cake images_cleanup [--dry-run]
|
||||
*/
|
||||
class ImagesCleanupCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function defaultName(): string
|
||||
{
|
||||
return 'images_cleanup';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\Console\ConsoleOptionParser $parser Parser
|
||||
* @return \Cake\Console\ConsoleOptionParser
|
||||
*/
|
||||
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
|
||||
{
|
||||
return $parser
|
||||
->setDescription(__('Löscht Bilddateien, die zu keiner Folie mehr gehören.'))
|
||||
->addOption('dry-run', [
|
||||
'help' => __('Nur anzeigen, nichts löschen.'),
|
||||
'boolean' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\Console\Arguments $args Arguments
|
||||
* @param \Cake\Console\ConsoleIo $io Console
|
||||
* @return int
|
||||
*/
|
||||
public function execute(Arguments $args, ConsoleIo $io): int
|
||||
{
|
||||
/** @var \App\Model\Table\SlidesTable $slides */
|
||||
$slides = $this->fetchTable('Slides');
|
||||
$referenced = [];
|
||||
$rows = $slides->find()
|
||||
->select(['poll_id', 'image'])
|
||||
->where(['image IS NOT' => null])
|
||||
->disableHydration()
|
||||
->all();
|
||||
foreach ($rows as $row) {
|
||||
$referenced[(int)$row['poll_id']][] = (string)$row['image'];
|
||||
}
|
||||
|
||||
$dryRun = (bool)$args->getOption('dry-run');
|
||||
$removed = (new ImageService())->cleanup($referenced, $dryRun);
|
||||
foreach ($removed as $path) {
|
||||
$io->out(($dryRun ? __('Verwaist: {0}', $path) : __('Gelöscht: {0}', $path)));
|
||||
}
|
||||
$io->success($dryRun
|
||||
? __('{0} verwaiste Datei(en) gefunden (nichts gelöscht).', count($removed))
|
||||
: __('{0} verwaiste Datei(en) entfernt.', count($removed)));
|
||||
|
||||
return static::CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user