Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m5s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m53s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m49s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 54s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m4s
- /uploads nur über das Portal: UploadController prüft Sitzung bzw. App-Token; frei nur die Dateien der Anmeldeseite (Logos, Symbole, Anmeldehintergrund, Stylesheet, Schrift); public/uploads/.htaccess leitet alles an index.php (Migration schreibt sie, da der Ordner vor dem Updater geschützt ist); Systemzustand prüft die Regel; nginx-Hinweis in docs/SECURITY.md - Passwort-Anmeldung abschaltbar (PasswordLogin): Login-Formular, Passwort vergessen, App-Token und /api/v1/config; nur mit verknüpftem Konto abschaltbar, automatische Rückkehr ohne nutzbaren Dienst, Notausgang INHAUS_PASSWORD_LOGIN - Titelbilder: profile_covers (bis 12), zufällig je Seitenaufruf - ImageCompressor: Uploads im Backend (SafeUpload) und WordPress-Import auf ≤ 2400 px komprimiert, Format bleibt Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
62 lines
2.3 KiB
PHP
62 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Support\ImageCompressor;
|
|
use Tests\TestCase;
|
|
|
|
class ImageCompressorTest extends TestCase
|
|
{
|
|
private function noise(int $width, int $height): \GdImage
|
|
{
|
|
// Rauschen wie bei einem Foto (einfarbige Testbilder wären winzig)
|
|
$small = imagecreatetruecolor(intdiv($width, 10), intdiv($height, 10));
|
|
for ($x = 0; $x < intdiv($width, 10); $x++) {
|
|
for ($y = 0; $y < intdiv($height, 10); $y++) {
|
|
imagesetpixel($small, $x, $y, random_int(0, 0xFFFFFF));
|
|
}
|
|
}
|
|
$image = imagecreatetruecolor($width, $height);
|
|
imagecopyresampled($image, $small, 0, 0, 0, 0, $width, $height, intdiv($width, 10), intdiv($height, 10));
|
|
|
|
return $image;
|
|
}
|
|
|
|
public function test_photos_are_shrunk_and_compressed_in_their_format(): void
|
|
{
|
|
$jpeg = tempnam(sys_get_temp_dir(), 'cmp').'.jpg';
|
|
imagejpeg($this->noise(4000, 3000), $jpeg, 97);
|
|
$before = filesize($jpeg);
|
|
|
|
ImageCompressor::compressFile($jpeg);
|
|
|
|
clearstatcache();
|
|
[$width, $height, $type] = getimagesize($jpeg);
|
|
$this->assertSame([2400, 1800, IMAGETYPE_JPEG], [$width, $height, $type]);
|
|
$this->assertLessThan($before / 2, filesize($jpeg));
|
|
|
|
// PNG bleibt PNG (Transparenz), nur kleiner in den Maßen
|
|
$png = tempnam(sys_get_temp_dir(), 'cmp').'.png';
|
|
$image = imagecreatetruecolor(3000, 1000);
|
|
imagesavealpha($image, true);
|
|
imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));
|
|
imagepng($image, $png);
|
|
ImageCompressor::compressFile($png);
|
|
clearstatcache();
|
|
[$width, , $type] = getimagesize($png);
|
|
$this->assertSame([2400, IMAGETYPE_PNG], [$width, $type]);
|
|
|
|
// GIF (Animationen) und kleine Bilder bleiben unangetastet
|
|
$gif = tempnam(sys_get_temp_dir(), 'cmp').'.gif';
|
|
imagegif(imagecreatetruecolor(3000, 3000), $gif);
|
|
$gifBefore = md5_file($gif);
|
|
ImageCompressor::compressFile($gif);
|
|
$this->assertSame($gifBefore, md5_file($gif));
|
|
|
|
$small = tempnam(sys_get_temp_dir(), 'cmp').'.jpg';
|
|
imagejpeg(imagecreatetruecolor(300, 200), $small, 90);
|
|
$smallBefore = md5_file($small);
|
|
ImageCompressor::compressFile($small);
|
|
$this->assertSame($smallBefore, md5_file($small));
|
|
}
|
|
}
|