diff options
Diffstat (limited to 'model/Image.php')
-rw-r--r-- | model/Image.php | 30 |
1 files changed, 15 insertions, 15 deletions
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 |