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
@@ -9,6 +9,7 @@ use App\Model\Table\PollsTable;
|
||||
use App\Model\Table\ResponsesTable;
|
||||
use App\Model\Table\SlidesTable;
|
||||
use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
use Cake\Routing\Router;
|
||||
|
||||
/**
|
||||
* Builds the JSON state polled by the presenter screen (/admin/{token}/state)
|
||||
@@ -131,7 +132,7 @@ class PollStateService
|
||||
'index' => $index,
|
||||
'count' => count($slides),
|
||||
'hiddenCount' => $this->Slides->find()->where(['poll_id' => $poll->id, 'is_hidden' => true])->count(),
|
||||
'slide' => $current ? $this->slidePayload($current) : null,
|
||||
'slide' => $current ? $this->slidePayload($current, $poll) : null,
|
||||
'results' => $current ? $this->results->forSlide($current) : null,
|
||||
];
|
||||
}
|
||||
@@ -155,7 +156,7 @@ class PollStateService
|
||||
'isHidden' => $slide->is_hidden,
|
||||
'index' => null,
|
||||
'count' => null,
|
||||
'slide' => $this->slidePayload($slide),
|
||||
'slide' => $this->slidePayload($slide, $poll),
|
||||
'results' => $this->results->forSlide($slide),
|
||||
];
|
||||
}
|
||||
@@ -208,7 +209,7 @@ class PollStateService
|
||||
$words !== null || $qa !== null ? 0 : (int)$hasResponded,
|
||||
$slide?->modified?->toUnixString() ?? 0,
|
||||
]),
|
||||
'slide' => $showResults ? $this->slidePayload($slide) : null,
|
||||
'slide' => $showResults ? $this->slidePayload($slide, $poll) : null,
|
||||
'results' => $showResults ? $this->participantResults($slide) : null,
|
||||
'words' => $words,
|
||||
'quiz' => $quiz,
|
||||
@@ -398,9 +399,10 @@ class PollStateService
|
||||
|
||||
/**
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @param \App\Model\Entity\Poll $poll Poll of the slide (the image URL contains its join code)
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function slidePayload(Slide $slide): array
|
||||
public function slidePayload(Slide $slide, Poll $poll): array
|
||||
{
|
||||
return [
|
||||
'id' => $slide->id,
|
||||
@@ -415,6 +417,14 @@ class PollStateService
|
||||
'embedUrl' => $slide->youtubeEmbedUrl(),
|
||||
'watchUrl' => $slide->youtubeWatchUrl(),
|
||||
] : null,
|
||||
// Image of the slide: URL (random file name), alternative text ('' = decorative), layout (top|side|full)
|
||||
'image' => $slide->hasImage() ? [
|
||||
'url' => Router::url(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image]),
|
||||
'alt' => (string)$slide->image_alt,
|
||||
'layout' => $slide->imageLayout(),
|
||||
'width' => $slide->image_width,
|
||||
'height' => $slide->image_height,
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user