Lege Bildfassungen an und liefere sie zwischengespeichert aus (ADR-63)
Vorschaubilder entstehen zusätzlich als klein (360 px) und mittel (960 px), Website-Bilder in den Breiten 640, 1280 und 1920. Auswahl, Listen und Karten laden die kleinen Fassungen; die Website nutzt srcset. Adressen tragen Größe und Version und werden dauerhaft zwischengespeichert (ETag, 304). Die Website-Route läuft ohne Sitzung und Cookies. Bestand füllt sich über die Warteschlange oder mit media:varianten. Die Optionsliste des CMS fragt nicht mehr je Eintrag ab. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0492133201
commit
63b42b366c
54 files changed
+1033
-82
No files matched your search
@@ -49,7 +49,7 @@ public function rows(Model $subject): array
|
||||
? (string) ($element->display_title ?: $element->working_title)
|
||||
: 'Medium fehlt',
|
||||
'image' => $element instanceof ContentElement
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at)
|
||||
: null,
|
||||
'kind' => $element?->editorialContentKind?->label,
|
||||
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
|
||||
@@ -134,7 +134,7 @@ public function describe(array $staged): array
|
||||
? (string) ($element->display_title ?: $element->working_title)
|
||||
: 'Medium fehlt',
|
||||
'image' => $element instanceof ContentElement
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at)
|
||||
: null,
|
||||
'kind' => $element?->editorialContentKind?->label,
|
||||
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
|
||||
|
||||
@@ -104,7 +104,7 @@ public static function previewUrl(?string $target): ?string
|
||||
return route('website.media', $element);
|
||||
}
|
||||
|
||||
return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path);
|
||||
return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -319,7 +319,7 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
|
||||
notice: $notice,
|
||||
visual: 'catalog',
|
||||
visualLabel: $kind,
|
||||
previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path) : null,
|
||||
previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path, 'mittel', $composition->updated_at) : null,
|
||||
missing: $missing,
|
||||
texts: $texts,
|
||||
);
|
||||
|
||||
@@ -221,7 +221,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
$missing[] = 'Kein Anzeigetitel gepflegt; die Karte zeigt den Arbeitstitel.';
|
||||
}
|
||||
|
||||
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null;
|
||||
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path, 'mittel', $shown->updated_at) : null;
|
||||
|
||||
return new CardSubject(
|
||||
title: $title,
|
||||
|
||||
@@ -115,7 +115,7 @@ private function renderSection(array $section, array $cells, int $index, RenderC
|
||||
$style = SectionStyle::fromStored($section['style'] ?? []);
|
||||
$columns = SectionLayouts::columns(array_column($cells, 'units'));
|
||||
// Hintergrundbild aus dem Medienmanager: öffentlich nur mit Website-Freigabe (WebsiteImage → WebsiteMedia).
|
||||
$imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview) : null;
|
||||
$imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview, 1920) : null;
|
||||
$hasImage = $imageUrl !== null;
|
||||
|
||||
$classes = [
|
||||
|
||||
@@ -86,7 +86,7 @@ public function elementId(mixed $value): ?int
|
||||
return is_int($id) ? $id : null;
|
||||
}
|
||||
|
||||
public function presentation(mixed $value): ?WebsitePresentation
|
||||
public function presentation(mixed $value, ?ContentElement $loaded = null): ?WebsitePresentation
|
||||
{
|
||||
$id = $this->elementId($value);
|
||||
|
||||
@@ -95,7 +95,8 @@ public function presentation(mixed $value): ?WebsitePresentation
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $this->presentations)) {
|
||||
$this->presentations[$id] = $this->media->present($id) ?? false;
|
||||
// Ein schon geladenes Medium wird weitergereicht (kein zweiter Zugriff je Eintrag in der Auswahl).
|
||||
$this->presentations[$id] = $this->media->present($loaded?->getKey() === $id ? $loaded : $id) ?? false;
|
||||
}
|
||||
|
||||
return $this->presentations[$id] ?: null;
|
||||
@@ -105,12 +106,12 @@ public function presentation(mixed $value): ?WebsitePresentation
|
||||
* Bildadresse für die Darstellung. Öffentlich nur freigegebene Medien (oder frühere CMS-Bilder ohne Zuordnung);
|
||||
* in der Redaktionsvorschau zusätzlich das Vorschaubild eines nicht freigegebenen Mediums.
|
||||
*/
|
||||
public function url(mixed $value, bool $preview = false): ?string
|
||||
public function url(mixed $value, bool $preview = false, ?int $width = null): ?string
|
||||
{
|
||||
$presentation = $this->presentation($value);
|
||||
|
||||
if ($presentation !== null) {
|
||||
return $presentation->kind === 'bild' ? $presentation->url : null;
|
||||
return $presentation->kind === 'bild' ? $presentation->urlForWidth($width) : null;
|
||||
}
|
||||
|
||||
$id = $this->elementId($value);
|
||||
@@ -122,7 +123,7 @@ public function url(mixed $value, bool $preview = false): ?string
|
||||
|
||||
$element = ContentElement::query()->find($id);
|
||||
|
||||
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at);
|
||||
}
|
||||
|
||||
$legacy = self::normalize($value);
|
||||
@@ -134,6 +135,14 @@ public function url(mixed $value, bool $preview = false): ?string
|
||||
return is_string($legacy) ? PublicMedia::url($legacy) : null;
|
||||
}
|
||||
|
||||
/** `srcset` des freigegebenen Bildes (mehrere Breiten), sonst null. Für Hero, Bild mit Text, Karten. */
|
||||
public function srcset(mixed $value): ?string
|
||||
{
|
||||
$presentation = $this->presentation($value);
|
||||
|
||||
return $presentation !== null && $presentation->kind === 'bild' ? $presentation->srcset : null;
|
||||
}
|
||||
|
||||
/** Alternativtext: Angabe im Widget, sonst der Alternativtext des Mediums. */
|
||||
public function alt(mixed $value, mixed $override = null): string
|
||||
{
|
||||
@@ -169,7 +178,7 @@ public function previewNotice(mixed $value, string $label = 'Das gewählte Bild'
|
||||
*
|
||||
* @return array{public: bool, state: string, title: string, note: string, thumb: ?string, manageUrl: ?string}|null
|
||||
*/
|
||||
public function status(mixed $value): ?array
|
||||
public function status(mixed $value, ?ContentElement $loaded = null): ?array
|
||||
{
|
||||
$value = self::normalize($value);
|
||||
|
||||
@@ -194,16 +203,16 @@ public function status(mixed $value): ?array
|
||||
];
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->with('editorialContentKind')->find($id);
|
||||
$element = $loaded?->getKey() === $id ? $loaded : ContentElement::query()->with('editorialContentKind')->find($id);
|
||||
|
||||
if ($element === null) {
|
||||
return ['public' => false, 'state' => 'missing', 'title' => 'Medium '.$id, 'note' => 'Das Medium gibt es nicht mehr.', 'thumb' => null, 'manageUrl' => null];
|
||||
}
|
||||
|
||||
$title = (string) ($element->display_title ?: $element->working_title);
|
||||
$thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
$thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at);
|
||||
$manageUrl = ContentElementResource::getUrl('view', ['record' => $element]);
|
||||
$public = $this->presentation($id) !== null;
|
||||
$public = $this->presentation($id, $element) !== null;
|
||||
|
||||
$note = match (true) {
|
||||
$public => 'Für die Website freigegeben.',
|
||||
@@ -292,7 +301,7 @@ public function options(?string $search = null, int $limit = 60): array
|
||||
$options = [];
|
||||
foreach ($elements as $element) {
|
||||
if (self::isSelectable($element)) {
|
||||
$options[$element->id] = $this->optionHtml($element->id);
|
||||
$options[$element->id] = $this->optionHtml($element->id, $element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,9 +309,9 @@ public function options(?string $search = null, int $limit = 60): array
|
||||
}
|
||||
|
||||
/** HTML-Bezeichnung einer Option oder des gewählten Werts (auch für frühere Pfade). */
|
||||
public function optionHtml(mixed $value): ?string
|
||||
public function optionHtml(mixed $value, ?ContentElement $loaded = null): ?string
|
||||
{
|
||||
$status = $this->status($value);
|
||||
$status = $this->status($value, $loaded);
|
||||
|
||||
if ($status === null) {
|
||||
return null;
|
||||
@@ -315,7 +324,7 @@ public function optionHtml(mixed $value): ?string
|
||||
default => ['warn', 'Website: nicht freigegeben'],
|
||||
};
|
||||
$thumb = $status['thumb'] !== null
|
||||
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy">'
|
||||
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy" decoding="async">'
|
||||
: '<span class="luf-media-option-empty" aria-hidden="true"></span>';
|
||||
|
||||
return '<span class="luf-media-option">'.$thumb
|
||||
|
||||
@@ -302,6 +302,7 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
'linkLabel' => filled($item['link_label'] ?? null) ? $item['link_label'] : self::DEFAULT_LINK_LABEL,
|
||||
'symbol' => HeadingAccent::symbol(['symbol' => $item['symbol'] ?? null]),
|
||||
'imageUrl' => $images->url($item['image'] ?? null, $context->preview),
|
||||
'imageSrcset' => $images->srcset($item['image'] ?? null),
|
||||
];
|
||||
|
||||
if ($context->preview && ($notice = $images->previewNotice($item['image'] ?? null, 'Das Bild der Karte „'.$item['title'].'“')) !== null) {
|
||||
|
||||
@@ -250,6 +250,7 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
return [
|
||||
'video' => $video,
|
||||
'imageUrl' => $images->url($image, $context->preview),
|
||||
'imageSrcset' => $images->srcset($image),
|
||||
'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null),
|
||||
'imageNotice' => $context->preview ? $images->previewNotice($image) : null,
|
||||
'actions' => $actions,
|
||||
|
||||
@@ -329,6 +329,7 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
|
||||
return [
|
||||
'imageUrl' => $imageUrl,
|
||||
'imageSrcset' => $imageUrl === null ? null : $images->srcset($image),
|
||||
'imageAlt' => $imageAlt,
|
||||
'imageNotice' => $context->preview ? $images->previewNotice($image) : null,
|
||||
'video' => $video,
|
||||
|
||||
@@ -130,7 +130,7 @@ protected function filmFieldData(?ContentElement $film): array
|
||||
? route('content.website-frame', ['element' => $film])
|
||||
: null,
|
||||
'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '',
|
||||
'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path) : null,
|
||||
'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path, 'mittel', $film->updated_at) : null,
|
||||
'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -349,6 +349,7 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
'clip' => $clip,
|
||||
'cardStyle' => $subject?->style ?? $this->cardStyle(),
|
||||
'imageUrl' => app(WebsiteImage::class)->url($imageRef, $context->preview),
|
||||
'imageSrcset' => app(WebsiteImage::class)->srcset($imageRef),
|
||||
'alt' => app(WebsiteImage::class)->alt($imageRef, $data['alt'] ?? null),
|
||||
'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($imageRef, 'Das Kartenbild') : null,
|
||||
'focus' => PremiumFields::focus($data, 66, 45),
|
||||
|
||||
@@ -65,7 +65,7 @@ protected function imageSourceFields(): array
|
||||
'composition' => $composition,
|
||||
'compositionTitle' => $composition instanceof Composition ? (string) ($composition->display_title ?: $composition->designation) : '',
|
||||
'compositionThumbnailUrl' => $composition instanceof Composition && app(CompositionStill::class)->hasThumbnail($composition)
|
||||
? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path)
|
||||
? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path, 'mittel', $composition->updated_at)
|
||||
: null,
|
||||
];
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Größenstufen eines Bildes (docs/architektur/bildvarianten.md).
|
||||
*
|
||||
* Neben der Hauptdatei (`vorschau/element-12.jpg`, „voll“: bis 2400 px bei Bildern, 640 px sonst) liegen daneben
|
||||
* kleinere JPEG-Fassungen, benannt nach der Hauptdatei (`element-12-klein.jpg`). Es gibt keine Spalte dafür: Die Hauptdatei
|
||||
* bleibt `thumbnail_path`, die Fassungen folgen der Namensregel. Fehlt eine Fassung, gilt die Hauptdatei (kein Bruch bei
|
||||
* Bestand, der noch nicht abgeleitet ist).
|
||||
*
|
||||
* Verwaltungsoberfläche (Disk `media_derived`):
|
||||
* - `klein` 360 px: Auswahl, Listen, Karten (Anzeige bis etwa 180 px, doppelt für scharfe Bildschirme)
|
||||
* - `mittel` 960 px: Detailansicht, Vorschau, Titelbild im Editor
|
||||
* - voll: die Hauptdatei
|
||||
*
|
||||
* Website (Disk `media_public`, `website/{id}/datei-{breite}.jpg`): Breiten {@see self::PUBLIC_WIDTHS}, daneben die
|
||||
* Hauptdatei `datei.jpg`. Eine Fassung entsteht nur, wenn die Quelle breiter ist (nie vergrößern).
|
||||
*
|
||||
* Geschrieben wird nur in der Warteschlange; der Web-Prozess liest.
|
||||
*/
|
||||
class ImageVariants
|
||||
{
|
||||
/** @var array<string, int> */
|
||||
public const SIZES = ['klein' => 360, 'mittel' => 960];
|
||||
|
||||
/** @var list<int> */
|
||||
public const PUBLIC_WIDTHS = [640, 1280, 1920];
|
||||
|
||||
private const QUALITY = 80;
|
||||
|
||||
public static function isSize(mixed $size): bool
|
||||
{
|
||||
return is_string($size) && array_key_exists($size, self::SIZES);
|
||||
}
|
||||
|
||||
public static function isPublicWidth(mixed $width): bool
|
||||
{
|
||||
return is_int($width) && in_array($width, self::PUBLIC_WIDTHS, true);
|
||||
}
|
||||
|
||||
/** `vorschau/element-12.jpg` → `vorschau/element-12-klein.jpg` */
|
||||
public static function path(string $base, string $size): string
|
||||
{
|
||||
$extension = pathinfo($base, PATHINFO_EXTENSION);
|
||||
$stem = $extension === '' ? $base : substr($base, 0, -(strlen($extension) + 1));
|
||||
|
||||
return $stem.'-'.$size.'.jpg';
|
||||
}
|
||||
|
||||
/** `website/12/datei.jpg` → `website/12/datei-640.jpg` */
|
||||
public static function publicPath(string $base, int $width): string
|
||||
{
|
||||
return self::path($base, (string) $width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pfad, der für die Größe ausgeliefert wird: die Fassung, wenn es sie gibt, sonst die Hauptdatei.
|
||||
*/
|
||||
public static function resolve(Filesystem $disk, string $base, ?string $size): string
|
||||
{
|
||||
if (! self::isSize($size)) {
|
||||
return $base;
|
||||
}
|
||||
|
||||
$variant = self::path($base, (string) $size);
|
||||
|
||||
return $disk->exists($variant) ? $variant : $base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt die Fassungen der Verwaltungsoberfläche zur Hauptdatei an (Warteschlange). Ist die Quelle nicht breiter als die
|
||||
* Stufe, entfällt die Fassung, und eine ältere wird entfernt.
|
||||
*
|
||||
* @return list<string> Pfade der geschriebenen Fassungen
|
||||
*/
|
||||
public static function generate(Filesystem $disk, string $base): array
|
||||
{
|
||||
$targets = [];
|
||||
|
||||
foreach (self::SIZES as $name => $width) {
|
||||
$targets[self::path($base, $name)] = $width;
|
||||
}
|
||||
|
||||
return self::write($disk, $disk, $base, $targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt die Breiten für die Website neben der öffentlichen Hauptdatei an. Nur JPEG-Quellen: andere Formate (PNG, GIF,
|
||||
* WebP) können Transparenz tragen, die ein JPEG nicht hält; sie bleiben unverändert.
|
||||
*
|
||||
* @return list<string> Pfade der geschriebenen Fassungen
|
||||
*/
|
||||
public static function generatePublic(Filesystem $source, Filesystem $target, string $sourcePath, string $publicBase): array
|
||||
{
|
||||
if (! in_array(strtolower(pathinfo($publicBase, PATHINFO_EXTENSION)), ['jpg', 'jpeg'], true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
|
||||
foreach (self::PUBLIC_WIDTHS as $width) {
|
||||
$targets[self::publicPath($publicBase, $width)] = $width;
|
||||
}
|
||||
|
||||
return self::write($source, $target, $sourcePath, $targets);
|
||||
}
|
||||
|
||||
/** Entfernt alle Fassungen zu einer öffentlichen Hauptdatei (Rücknahme, Ersatz). */
|
||||
public static function deletePublic(Filesystem $disk, string $publicBase): void
|
||||
{
|
||||
foreach (self::PUBLIC_WIDTHS as $width) {
|
||||
$disk->delete(self::publicPath($publicBase, $width));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int> $targets Zielpfad → Breite
|
||||
* @return list<string>
|
||||
*/
|
||||
private static function write(Filesystem $source, Filesystem $target, string $sourcePath, array $targets): array
|
||||
{
|
||||
if (! $source->exists($sourcePath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$bytes = $source->get($sourcePath);
|
||||
$image = is_string($bytes) && $bytes !== '' ? @imagecreatefromstring($bytes) : false;
|
||||
|
||||
if ($image === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
$written = [];
|
||||
|
||||
foreach ($targets as $path => $targetWidth) {
|
||||
if ($width <= $targetWidth) {
|
||||
$target->delete($path);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$encoded = self::scaled($image, $width, $height, $targetWidth);
|
||||
|
||||
if ($encoded !== null && $target->put($path, $encoded)) {
|
||||
$written[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
imagedestroy($image);
|
||||
|
||||
return $written;
|
||||
}
|
||||
|
||||
private static function scaled(\GdImage $image, int $width, int $height, int $targetWidth): ?string
|
||||
{
|
||||
$targetHeight = (int) max(1, round($height * ($targetWidth / max(1, $width))));
|
||||
$canvas = imagecreatetruecolor($targetWidth, $targetHeight);
|
||||
imagefill($canvas, 0, 0, (int) imagecolorallocate($canvas, 255, 255, 255));
|
||||
imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
||||
imageinterlace($canvas, true);
|
||||
ob_start();
|
||||
imagejpeg($canvas, null, self::QUALITY);
|
||||
$bytes = ob_get_clean();
|
||||
imagedestroy($canvas);
|
||||
|
||||
return is_string($bytes) && $bytes !== '' ? $bytes : null;
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ public function place(ContentElement $element, string $incoming): void
|
||||
}
|
||||
|
||||
if ($element->output_class === 'bild') {
|
||||
ImageVariants::generate(Storage::disk('media_derived'), $target);
|
||||
$element->thumbnail_path = $target;
|
||||
$element->thumbnail_source = 'eigen';
|
||||
} else {
|
||||
@@ -97,6 +98,7 @@ public function place(ContentElement $element, string $incoming): void
|
||||
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
$element->touch();
|
||||
Storage::disk('cms_incoming')->delete($incoming);
|
||||
}
|
||||
|
||||
|
||||
@@ -335,6 +335,7 @@ private function frame(ContentElement $element, ContentElementVersion $version,
|
||||
return;
|
||||
}
|
||||
|
||||
ImageVariants::generate($disk, $target);
|
||||
$element->thumbnail_path = $target;
|
||||
if (! filled($element->thumbnail_alt)) {
|
||||
$element->thumbnail_alt = $element->working_title;
|
||||
@@ -344,6 +345,7 @@ private function frame(ContentElement $element, ContentElementVersion $version,
|
||||
$element->thumbnail_source = 'frame:'.$version->id.'@0';
|
||||
}
|
||||
$element->save();
|
||||
$element->touch();
|
||||
}
|
||||
|
||||
private function still(ContentElement|Composition $subject, Filesystem $disk, string $file, string $name): void
|
||||
@@ -388,6 +390,7 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
|
||||
|
||||
$path = 'vorschau/'.$name.'.jpg';
|
||||
Storage::disk('media_derived')->put($path, $bytes);
|
||||
ImageVariants::generate(Storage::disk('media_derived'), $path);
|
||||
$subject->thumbnail_path = $path;
|
||||
|
||||
if (! filled($subject->thumbnail_alt)) {
|
||||
@@ -396,6 +399,9 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
|
||||
|
||||
$subject->thumbnail_error = null;
|
||||
$subject->save();
|
||||
// Die Adresse trägt die Version (updated_at) und wird dauerhaft zwischengespeichert: Ein neu abgeleitetes Bild
|
||||
// unter gleichem Pfad muss die Version ändern, auch wenn sonst nichts an der Zeile anders ist.
|
||||
$subject->touch();
|
||||
}
|
||||
|
||||
private function rememberElement(ContentElement $element, string $source): void
|
||||
|
||||
@@ -2,14 +2,37 @@
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
|
||||
class ThumbnailRef
|
||||
{
|
||||
public static function url(string $route, string $kind, int $id, mixed $path): ?string
|
||||
/**
|
||||
* Adresse eines Vorschaubildes.
|
||||
*
|
||||
* @param string|null $size `klein` (Auswahl, Listen, Karten), `mittel` (Detail, Vorschau) oder null für die volle Datei
|
||||
* @param CarbonInterface|int|string|null $version Stand des Bildes (zum Beispiel `updated_at`). Mit Version darf der Browser das Bild
|
||||
* dauerhaft behalten; ohne Version fragt er jedes Mal nach (ETag).
|
||||
*/
|
||||
public static function url(string $route, string $kind, int $id, mixed $path, ?string $size = null, CarbonInterface|int|string|null $version = null): ?string
|
||||
{
|
||||
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return route($route, ['kind' => $kind, 'subject' => $id]);
|
||||
$query = [];
|
||||
|
||||
if (ImageVariants::isSize($size)) {
|
||||
$query['g'] = $size;
|
||||
}
|
||||
|
||||
if ($version instanceof CarbonInterface) {
|
||||
$version = $version->getTimestamp();
|
||||
}
|
||||
|
||||
if ($version !== null && $version !== '') {
|
||||
$query['v'] = $version;
|
||||
}
|
||||
|
||||
return route($route, ['kind' => $kind, 'subject' => $id] + $query);
|
||||
}
|
||||
}
|
||||
@@ -45,10 +45,37 @@ public function present(ContentElement|int $element): ?WebsitePresentation
|
||||
'audio' => 'audio',
|
||||
default => 'bild',
|
||||
},
|
||||
url: route('website.media', $element),
|
||||
// Bilder tragen den Zeitpunkt der Freigabe in der Adresse (dauerhaft zwischenspeicherbar); Film und Hörstück bleiben unverändert.
|
||||
url: $element->output_class === 'film' || $element->output_class === 'audio'
|
||||
? route('website.media', $element)
|
||||
: route('website.media', ['element' => $element, 'v' => $element->website_released_at->getTimestamp()]),
|
||||
srcset: $this->srcset($element, $path),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* `srcset` eines freigegebenen JPEG-Bildes: die Breiten aus {@see ImageVariants::PUBLIC_WIDTHS} und die volle Datei.
|
||||
* Fehlt eine Breite noch (Bestand), liefert die Adresse die volle Datei und stößt das Anlegen an; die Beschreibung bleibt
|
||||
* dann ungenau, das Bild aber richtig. PNG, GIF und WebP bleiben ohne Fassungen (Transparenz).
|
||||
*/
|
||||
private function srcset(ContentElement $element, string $path): ?string
|
||||
{
|
||||
if ($element->output_class !== 'bild' || ! in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ['jpg', 'jpeg'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$version = $element->website_released_at->getTimestamp();
|
||||
$entries = [];
|
||||
|
||||
foreach (ImageVariants::PUBLIC_WIDTHS as $width) {
|
||||
$entries[] = route('website.media', ['element' => $element, 'w' => $width, 'v' => $version]).' '.$width.'w';
|
||||
}
|
||||
|
||||
$entries[] = route('website.media', ['element' => $element, 'v' => $version]).' 2400w';
|
||||
|
||||
return implode(', ', $entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slideshow: freigegebene Medien in der angegebenen Reihenfolge. Nicht freigegebene Einträge entfallen.
|
||||
*
|
||||
|
||||
@@ -15,5 +15,19 @@ public function __construct(
|
||||
public readonly ?string $credit,
|
||||
public readonly string $kind,
|
||||
public readonly string $url,
|
||||
/** Bildadressen in mehreren Breiten für `srcset` (nur Bilder, deren Breiten die Warteschlange anlegt), sonst null. */
|
||||
public readonly ?string $srcset = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Adresse in einer der Breiten aus {@see ImageVariants::PUBLIC_WIDTHS}; ohne Breiten (oder bei anderer Breite) die volle Datei.
|
||||
*/
|
||||
public function urlForWidth(?int $width): string
|
||||
{
|
||||
if ($width === null || $this->srcset === null || ! ImageVariants::isPublicWidth($width)) {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
return $this->url.(str_contains($this->url, '?') ? '&' : '?').'w='.$width;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user