From 7c63424ea61c1760c262649e1670b2d48429324c Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 18 Nov 2026 22:13:12 +0100 Subject: [PATCH] =?UTF-8?q?Leite=20Website-Bilder=20bis=202400=20px=20stat?= =?UTF-8?q?t=20in=20Vorschaugr=C3=B6=C3=9Fe=20ab.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ein Bild (Ausgabeart „bild“) dient über die Website-Freigabe auch als Einstieg und Abschnittshintergrund; 640 px wären bei 1440 px Fensterbreite sichtbar unscharf. Bilder werden nie vergrößert, transparente Flächen werden weiß. Filmstandbilder und Modulvorschauen bleiben bei 640 px. Co-Authored-By: Claude Opus 5.5 --- app/Domain/Media/ThumbnailDeriver.php | 8 ++- tests/Feature/WebsiteImageResolutionTest.php | 68 ++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/WebsiteImageResolutionTest.php diff --git a/app/Domain/Media/ThumbnailDeriver.php b/app/Domain/Media/ThumbnailDeriver.php index 53ccbdd..6db8103 100644 --- a/app/Domain/Media/ThumbnailDeriver.php +++ b/app/Domain/Media/ThumbnailDeriver.php @@ -291,9 +291,15 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st $width = imagesx($image); $height = imagesy($image); - $targetWidth = 640; + // Bilder (Ausgabeart „bild“) dienen auch als Website-Ableitung für Einstieg und Hintergrund. 640 px wären dort + // sichtbar unscharf; deshalb bis 2400 px, nie vergrößert. Filmstandbilder und Modulvorschauen bleiben bei 640 px. + $targetWidth = $subject instanceof ContentElement && $subject->output_class === 'bild' + ? max(1, min(2400, $width)) + : 640; $targetHeight = (int) max(1, round($height * ($targetWidth / max(1, $width)))); $canvas = imagecreatetruecolor($targetWidth, $targetHeight); + // Transparente Flächen (PNG, GIF) werden im JPEG weiß statt schwarz. + imagefill($canvas, 0, 0, (int) imagecolorallocate($canvas, 255, 255, 255)); imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height); ob_start(); imagejpeg($canvas, null, 82); diff --git a/tests/Feature/WebsiteImageResolutionTest.php b/tests/Feature/WebsiteImageResolutionTest.php new file mode 100644 index 0000000..90ffa5e --- /dev/null +++ b/tests/Feature/WebsiteImageResolutionTest.php @@ -0,0 +1,68 @@ +accept('cms/gross.png', $this->png(3000, 1500, transparent: true)); + [$width, $height] = getimagesizefromstring(Storage::disk('media_derived')->get($element->thumbnail_path)); + $this->assertSame([2400, 1200], [$width, $height]); + + $image = imagecreatefromstring(Storage::disk('media_derived')->get($element->thumbnail_path)); + $this->assertGreaterThan(240, imagecolorat($image, 5, 5) & 0xFF, 'Transparenz wird weiß, nicht schwarz.'); + } + + public function test_small_images_are_not_enlarged(): void + { + $element = $this->accept('cms/klein.png', $this->png(800, 450)); + [$width, $height] = getimagesizefromstring(Storage::disk('media_derived')->get($element->thumbnail_path)); + $this->assertSame([800, 450], [$width, $height]); + } + + private function accept(string $path, string $bytes): ContentElement + { + Storage::disk('cms_incoming')->put($path, $bytes); + + return app(WebsiteIntake::class)->acceptImage($path, 'Testbild')->refresh(); + } + + private function png(int $width, int $height, bool $transparent = false): string + { + $image = imagecreatetruecolor($width, $height); + + if ($transparent) { + imagesavealpha($image, true); + imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127)); + } else { + imagefill($image, 0, 0, imagecolorallocate($image, 30, 90, 160)); + } + + ob_start(); + imagepng($image); + + return (string) ob_get_clean(); + } +}