Leite Website-Bilder bis 2400 px statt in Vorschaugröße ab.

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 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-18 22:13:12 +01:00
1 parent 13530b8171
commit 7c63424ea6
2 files changed
+75 -1

No files matched your search

+7 -1
View File
@@ -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);
@@ -0,0 +1,68 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ContentElement;
use App\Domain\Media\WebsiteIntake;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
* Website-Bilder dienen als Einstieg und Abschnittshintergrund. Ihre Ableitung darf nicht auf Vorschaugröße (640 px)
* schrumpfen, wird aber auch nicht vergrößert. Transparente Flächen werden weiß.
*/
class WebsiteImageResolutionTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('cms_incoming');
Storage::fake('media_derived');
Storage::fake('media_public');
}
public function test_large_images_keep_up_to_2400_pixels_and_transparency_becomes_white(): void
{
$element = $this->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();
}
}