diff options
| author | polo <ordipolo@gmx.fr> | 2022-07-06 01:59:48 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2022-07-06 01:59:48 +0200 |
| commit | ed5df18ed28a338ecd763e6492991ccbf5e23eb0 (patch) | |
| tree | d1112d52bf89856f0edbb2dfbdb02b3423c50ecd /model | |
| parent | 9608a1de748363403b410cc4193f791419e6efc0 (diff) | |
| download | melaine-ed5df18ed28a338ecd763e6492991ccbf5e23eb0.tar.gz melaine-ed5df18ed28a338ecd763e6492991ccbf5e23eb0.tar.bz2 melaine-ed5df18ed28a338ecd763e6492991ccbf5e23eb0.zip | |
rangement du code
Diffstat (limited to 'model')
| -rw-r--r-- | model/Album.php | 8 | ||||
| -rw-r--r-- | model/Image.php | 30 |
2 files changed, 19 insertions, 19 deletions
diff --git a/model/Album.php b/model/Album.php index 3f13939..95dac50 100644 --- a/model/Album.php +++ b/model/Album.php | |||
| @@ -51,7 +51,7 @@ class Album extends Article | |||
| 51 | require('model/Image.php'); | 51 | require('model/Image.php'); |
| 52 | $Image = new Image(false); | 52 | $Image = new Image(false); |
| 53 | $Image->upload(); | 53 | $Image->upload(); |
| 54 | $Image->makeThumbnail(); | 54 | $Image->makeThumbnail(201); |
| 55 | 55 | ||
| 56 | $erreur = $Image->erreur; | 56 | $erreur = $Image->erreur; |
| 57 | if(!empty($erreur)) | 57 | if(!empty($erreur)) |
| @@ -181,7 +181,7 @@ class Album extends Article | |||
| 181 | require('model/Image.php'); | 181 | require('model/Image.php'); |
| 182 | $Image = new Image(false); | 182 | $Image = new Image(false); |
| 183 | $Image->upload(); | 183 | $Image->upload(); |
| 184 | $Image->makeThumbnail(); | 184 | $Image->makeThumbnail(201); |
| 185 | $erreur = $Image->erreur; | 185 | $erreur = $Image->erreur; |
| 186 | if(!empty($erreur)) | 186 | if(!empty($erreur)) |
| 187 | { | 187 | { |
| @@ -205,12 +205,12 @@ class Album extends Article | |||
| 205 | // delete | 205 | // delete |
| 206 | public function delete() | 206 | public function delete() |
| 207 | { | 207 | { |
| 208 | parent::delete(); | 208 | parent::delete(); // json |
| 209 | 209 | ||
| 210 | if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); | 210 | if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); |
| 211 | { | 211 | { |
| 212 | $this->format = 'html'; | 212 | $this->format = 'html'; |
| 213 | parent::delete(); | 213 | parent::delete(); // html |
| 214 | } | 214 | } |
| 215 | } | 215 | } |
| 216 | } | 216 | } |
diff --git a/model/Image.php b/model/Image.php index 05773e9..59665e9 100644 --- a/model/Image.php +++ b/model/Image.php | |||
| @@ -16,8 +16,8 @@ class Image | |||
| 16 | public function __construct($ajax) | 16 | public function __construct($ajax) |
| 17 | { | 17 | { |
| 18 | // get envoyé avec le javascript | 18 | // get envoyé avec le javascript |
| 19 | $this->page = $_GET['page']; | ||
| 20 | $this->ajax = $ajax; | 19 | $this->ajax = $ajax; |
| 20 | $this->page = $_GET['page']; | ||
| 21 | $this->path = 'data/' . $this->page . '/images/'; | 21 | $this->path = 'data/' . $this->page . '/images/'; |
| 22 | $this->pathMini = 'data/' . $this->page . '/images-mini/'; | 22 | $this->pathMini = 'data/' . $this->page . '/images-mini/'; |
| 23 | } | 23 | } |
| @@ -60,11 +60,19 @@ class Image | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | // miniatures des photos | 62 | // miniatures des photos |
| 63 | public function makeThumbnail() | 63 | public function makeThumbnail($largeur) |
| 64 | { | 64 | { |
| 65 | global $imageLibrary; | 65 | global $imageLibrary; |
| 66 | 66 | ||
| 67 | if($imageLibrary == 'gd') | 67 | if($imageLibrary == 'imagick') |
| 68 | { | ||
| 69 | $Image = new Imagick($this->path . $_FILES['upload']['name']); | ||
| 70 | // 0 signifie qu'on conserve les proportions | ||
| 71 | $Image->thumbnailImage($largeur, 0); | ||
| 72 | // écriture dans un fichier | ||
| 73 | $Image->writeImage($this->pathMini . $this->pathInfos['filename'] . '-mini.' . $this->pathInfos['extension']); | ||
| 74 | } | ||
| 75 | elseif($imageLibrary == 'gd') | ||
| 68 | { | 76 | { |
| 69 | // cette fonction fonctionne pour tous les formats | 77 | // cette fonction fonctionne pour tous les formats |
| 70 | $source = imagecreatefromstring(file_get_contents($this->path . $_FILES['upload']['name'])); | 78 | $source = imagecreatefromstring(file_get_contents($this->path . $_FILES['upload']['name'])); |
| @@ -74,15 +82,15 @@ class Image | |||
| 74 | $forme = imagesy($source) / imagesx($source); | 82 | $forme = imagesy($source) / imagesx($source); |
| 75 | var_dump($forme); | 83 | var_dump($forme); |
| 76 | 84 | ||
| 77 | if(imagesx($source) > 201) | 85 | if(imagesx($source) > $largeur) |
| 78 | { | 86 | { |
| 79 | // créer un rectangle noir | 87 | // créer un rectangle noir |
| 80 | $destination = imagecreatetruecolor(201, 201 * $forme); | 88 | $destination = imagecreatetruecolor($largeur, $largeur * $forme); |
| 81 | var_dump($destination); | 89 | //var_dump($destination); |
| 82 | 90 | ||
| 83 | // sélectionne un rectangle dans l'image source | 91 | // sélectionne un rectangle dans l'image source |
| 84 | // et le place dans un rectangle dans la nouvelle | 92 | // et le place dans un rectangle dans la nouvelle |
| 85 | imagecopyresampled($destination, $source, 0, 0, 0, 0, 201, 201 * $forme, imagesx($source), imagesy($source)); | 93 | imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur, $largeur * $forme, imagesx($source), imagesy($source)); |
| 86 | 94 | ||
| 87 | // envoie l'image dans un fichier | 95 | // envoie l'image dans un fichier |
| 88 | imagejpeg($destination, $nomMiniImage); | 96 | imagejpeg($destination, $nomMiniImage); |
| @@ -92,14 +100,6 @@ class Image | |||
| 92 | imagejpeg($source, $nomMiniImage); | 100 | imagejpeg($source, $nomMiniImage); |
| 93 | } | 101 | } |
| 94 | } | 102 | } |
| 95 | elseif($imageLibrary == 'imagick') | ||
| 96 | { | ||
| 97 | $Image = new Imagick($this->path . $_FILES['upload']['name']); | ||
| 98 | // 0 signifie qu'on conserve les proportions | ||
| 99 | $Image->thumbnailImage(201, 0); | ||
| 100 | // écriture dans un fichier | ||
| 101 | $Image->writeImage($this->pathMini . $this->pathInfos['filename'] . '-mini.' . $this->pathInfos['extension']); | ||
| 102 | } | ||
| 103 | else | 103 | else |
| 104 | { | 104 | { |
| 105 | // utiliser la grande image si il est impossible de créer une miniature | 105 | // utiliser la grande image si il est impossible de créer une miniature |
