From 0026fb32c23cc7333039c589c4fffa592ac45c78 Mon Sep 17 00:00:00 2001 From: julien Date: Fri, 27 Mar 2026 17:20:13 +0100 Subject: [PATCH] JPEG instead of PNG --- app/Models/Media.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Models/Media.php b/app/Models/Media.php index 2196e40..c68b0ce 100644 --- a/app/Models/Media.php +++ b/app/Models/Media.php @@ -50,26 +50,25 @@ class Media extends DB\SQL\Mapper // pour dériver un texte alternatif lisible. public function upload(string $srcPath, string $originalName = ''): int { - // Image::dump() gère le chargement, la transparence et la compression. - // $path='' indique à F3 que le chemin est absolu. + // Image::dump() gère le chargement et la compression. + // Attention : en JPEG, la transparence n'est pas conservée. try { $img = new Image($srcPath, false, ''); } catch (Throwable) { - throw new RuntimeException('Fichier image invalide ou format non supporté (JPG, PNG, WebP).'); + throw new RuntimeException('Fichier image invalide ou format source non supporté.'); } - $data = $img->dump('png', 9); // sans perte, compression maximale + $data = $img->dump('jpeg', 85); - // Supprimer le fichier intermédiaire déposé par Web::receive(). - @unlink($srcPath); - - $fileName = bin2hex(random_bytes(16)) . '.png'; + $fileName = bin2hex(random_bytes(16)) . '.jpg'; $target = app_public_media_dir() . '/' . $fileName; if (!Base::instance()->write($target, $data)) { throw new RuntimeException('Impossible d\'enregistrer cette image.'); } + @unlink($srcPath); + $this->reset(); $this->file_name = $fileName; $this->alt = $originalName !== '' ? self::altFromFilename($originalName) : '';