From 4529a54d6d7507508e5aaca2d7b4b63f3aa5c56d Mon Sep 17 00:00:00 2001 From: git-pc-greta Date: Mon, 16 Sep 2024 15:30:35 +0200 Subject: debug GD conversion implicite calcul de pixels --- model/Image.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/model/Image.php b/model/Image.php index d77cfb1..c17837f 100644 --- a/model/Image.php +++ b/model/Image.php @@ -13,7 +13,7 @@ class Image public $pathMini; public $FileName; // après sécurisation public $permissions; - public $width; + public int $width; public $pathInfos; public $erreur; @@ -42,7 +42,7 @@ class Image $this->FileName = $fileName; } - public function setThumbnailWidth($width) + public function setThumbnailWidth(int $width) { $this->width = $width; } @@ -110,16 +110,18 @@ class Image // on créera un jpg quelque soit l'image d'origine // nécessite une correction du html dans Article::makeHtmlMiniImages() $nomMiniImage = $this->pathMini . $this->pathInfos['filename'] . '-mini.jpg'; - $forme = imagesy($source) / imagesx($source); + $ratio = imagesy($source) / imagesx($source); if(imagesx($source) > $this->width) { + $height = intval($this->width * $ratio); // GD veut des pixels entiers + // créer un rectangle noir - $destination = imagecreatetruecolor($this->width, $this->width * $forme); + $destination = imagecreatetruecolor($this->width, $height); // sélectionne un rectangle dans l'image source // et le place dans un rectangle dans la nouvelle - imagecopyresampled($destination, $source, 0, 0, 0, 0, $this->width, $this->width * $forme, imagesx($source), imagesy($source)); + imagecopyresampled($destination, $source, 0, 0, 0, 0, $this->width, $height, imagesx($source), imagesy($source)); // envoie l'image dans un fichier imagejpeg($destination, $nomMiniImage); -- cgit v1.2.3