diff options
Diffstat (limited to 'model/Image.php')
-rw-r--r-- | model/Image.php | 12 |
1 files 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 | |||
13 | public $pathMini; | 13 | public $pathMini; |
14 | public $FileName; // après sécurisation | 14 | public $FileName; // après sécurisation |
15 | public $permissions; | 15 | public $permissions; |
16 | public $width; | 16 | public int $width; |
17 | public $pathInfos; | 17 | public $pathInfos; |
18 | public $erreur; | 18 | public $erreur; |
19 | 19 | ||
@@ -42,7 +42,7 @@ class Image | |||
42 | $this->FileName = $fileName; | 42 | $this->FileName = $fileName; |
43 | } | 43 | } |
44 | 44 | ||
45 | public function setThumbnailWidth($width) | 45 | public function setThumbnailWidth(int $width) |
46 | { | 46 | { |
47 | $this->width = $width; | 47 | $this->width = $width; |
48 | } | 48 | } |
@@ -110,16 +110,18 @@ class Image | |||
110 | // on créera un jpg quelque soit l'image d'origine | 110 | // on créera un jpg quelque soit l'image d'origine |
111 | // nécessite une correction du html dans Article::makeHtmlMiniImages() | 111 | // nécessite une correction du html dans Article::makeHtmlMiniImages() |
112 | $nomMiniImage = $this->pathMini . $this->pathInfos['filename'] . '-mini.jpg'; | 112 | $nomMiniImage = $this->pathMini . $this->pathInfos['filename'] . '-mini.jpg'; |
113 | $forme = imagesy($source) / imagesx($source); | 113 | $ratio = imagesy($source) / imagesx($source); |
114 | 114 | ||
115 | if(imagesx($source) > $this->width) | 115 | if(imagesx($source) > $this->width) |
116 | { | 116 | { |
117 | $height = intval($this->width * $ratio); // GD veut des pixels entiers | ||
118 | |||
117 | // créer un rectangle noir | 119 | // créer un rectangle noir |
118 | $destination = imagecreatetruecolor($this->width, $this->width * $forme); | 120 | $destination = imagecreatetruecolor($this->width, $height); |
119 | 121 | ||
120 | // sélectionne un rectangle dans l'image source | 122 | // sélectionne un rectangle dans l'image source |
121 | // et le place dans un rectangle dans la nouvelle | 123 | // et le place dans un rectangle dans la nouvelle |
122 | imagecopyresampled($destination, $source, 0, 0, 0, 0, $this->width, $this->width * $forme, imagesx($source), imagesy($source)); | 124 | imagecopyresampled($destination, $source, 0, 0, 0, 0, $this->width, $height, imagesx($source), imagesy($source)); |
123 | 125 | ||
124 | // envoie l'image dans un fichier | 126 | // envoie l'image dans un fichier |
125 | imagejpeg($destination, $nomMiniImage); | 127 | imagejpeg($destination, $nomMiniImage); |