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>
69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?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();
|
|
}
|
|
}
|