Add optional images to slides
CI / Deploy / PHP 8.4 (push) Successful in 1m10s
CI / Deploy / PHP 8.5 (push) Successful in 1m16s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

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:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-14 23:17:37 +01:00
1 parent 8c7818ee40
commit a395b50894
30 files changed
+1705 -11

No files matched your search

+5
View File
@@ -43,6 +43,11 @@ THROTTLE_RECOVER_PER_HOUR=5
THROTTLE_VOTES_PER_MINUTE=600
# How often presenter and participant pages poll for updates (ms)
POLL_INTERVAL_MS=2000
# Slide images: directory (default data/uploads; in containers e.g. /data/uploads), largest upload in MB
# (PHP's upload_max_filesize and post_max_size must allow it) and slides with an image per poll
# UPLOADS_PATH=/var/www/plenario-uploads
IMAGE_MAX_UPLOAD_MB=10
IMAGE_MAX_PER_POLL=20
# Embedded slides (/e/{key}/{slide}, e.g. Canva): heartbeat interval and timeout until pause (s)
EMBED_HEARTBEAT_SECONDS=5
EMBED_TIMEOUT_SECONDS=20
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
/**
* One optional image per slide. The (scaled) file lives in the upload directory, see
* \App\Service\ImageService; the table only holds its random file name and how to show it.
*/
class AddImageToSlides extends BaseMigration
{
/**
* @return void
*/
public function up(): void
{
$table = $this->table('slides');
$columns = [
// file name inside the poll's upload directory (null = no image)
'image' => ['string', ['null' => true, 'default' => null, 'limit' => 40]],
// alternative text, '' = purely decorative image
'image_alt' => ['string', ['null' => true, 'default' => null, 'limit' => 255]],
// top | side | full (null = default of the slide type)
'image_layout' => ['string', ['null' => true, 'default' => null, 'limit' => 8]],
'image_width' => ['integer', ['null' => true, 'default' => null]],
'image_height' => ['integer', ['null' => true, 'default' => null]],
];
$changed = false;
foreach ($columns as $name => [$type, $options]) {
if (!$table->hasColumn($name)) {
$table->addColumn($name, $type, $options);
$changed = true;
}
}
if ($changed) {
$table->update();
}
}
/**
* @return void
*/
public function down(): void
{
$table = $this->table('slides');
foreach (['image', 'image_alt', 'image_layout', 'image_width', 'image_height'] as $name) {
if ($table->hasColumn($name)) {
$table->removeColumn($name);
}
}
$table->update();
}
}
+12
View File
@@ -50,6 +50,18 @@ return [
'votesPerMinute' => (int)env('THROTTLE_VOTES_PER_MINUTE', 600),
],
'pollIntervalMs' => (int)env('POLL_INTERVAL_MS', 2000),
// Slide images (see \App\Service\ImageService): scaled and re-encoded as WebP, stored outside webroot.
'images' => [
// One sub directory per poll. In containers keep it on the volume, e.g. /data/uploads.
'path' => (string)env('UPLOADS_PATH', ROOT . DS . 'data' . DS . 'uploads'),
// Largest accepted upload (the original, before scaling). PHP's upload_max_filesize/post_max_size must allow it.
'maxUploadBytes' => (int)env('IMAGE_MAX_UPLOAD_MB', 10) * 1024 * 1024,
// Longest edge after scaling, in pixels.
'maxEdge' => 1600,
'quality' => 82,
// Slides with an image per poll.
'maxPerPoll' => (int)env('IMAGE_MAX_PER_POLL', 20),
],
// Slides embedded in other presentation software (/e/{key}/{slide}, e.g. Canva).
'embed' => [
// A visible embedded slide reports every N seconds that it is still on screen ...
+4
View File
@@ -33,6 +33,10 @@ return function (RouteBuilder $routes): void {
$builder->connect('/p/{code}/state', 'Participate::state', ['_name' => 'participate:state'])
->setPatterns(['code' => '[A-Za-z0-9-]{4,16}'])
->setPass(['code']);
// Slide images (also used by presenter and embed): random file name, only images of this poll.
$builder->connect('/p/{code}/img/{file}', 'Participate::image', ['_name' => 'participate:image'])
->setPatterns(['code' => '[A-Za-z0-9-]{4,16}', 'file' => '[a-f0-9]{24}\.webp'])
->setPass(['code', 'file']);
$builder->connect('/p/{code}/vote', 'Participate::vote', ['_name' => 'participate:vote'])
->setPatterns(['code' => '[A-Za-z0-9-]{4,16}'])
->setPass(['code'])