diff options
author | polo <ordipolo@gmx.fr> | 2022-02-18 05:38:40 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2022-02-18 05:38:40 +0100 |
commit | 9a1fb624fd1089087bd363551ba64f5862d9919f (patch) | |
tree | 87f33f1b1bede404efa2cfd8f4285d32e149d986 /model/Image.php | |
parent | f2c1f219dcd6e25b812d4dbed46f4c0c30541d83 (diff) | |
download | melaine-9a1fb624fd1089087bd363551ba64f5862d9919f.zip |
miniatures GD
Diffstat (limited to 'model/Image.php')
-rw-r--r-- | model/Image.php | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/model/Image.php b/model/Image.php index 8ebcd16..c305984 100644 --- a/model/Image.php +++ b/model/Image.php | |||
@@ -5,7 +5,10 @@ class Image | |||
5 | { | 5 | { |
6 | private const MAX_WEIGHT = 2000000; // à adapter au php.ini | 6 | private const MAX_WEIGHT = 2000000; // à adapter au php.ini |
7 | private $page; | 7 | private $page; |
8 | private $ajax = false; // vaut true avec le ckeditor | 8 | private $ajax; // vaut true avec le ckeditor |
9 | public $path; | ||
10 | public $pathMini; | ||
11 | public $pathInfos; | ||
9 | public $erreur; | 12 | public $erreur; |
10 | 13 | ||
11 | public function __construct($ajax) | 14 | public function __construct($ajax) |
@@ -13,14 +16,14 @@ class Image | |||
13 | // get envoyé avec le javascript | 16 | // get envoyé avec le javascript |
14 | $this->page = $_GET['page']; | 17 | $this->page = $_GET['page']; |
15 | $this->ajax = $ajax; | 18 | $this->ajax = $ajax; |
19 | $this->path = 'data/' . $this->page . '/images/'; | ||
20 | $this->pathMini = 'data/' . $this->page . '/images-mini/'; | ||
16 | } | 21 | } |
17 | 22 | ||
18 | // GET | 23 | // GET |
19 | 24 | ||
20 | // SET | 25 | // SET |
21 | 26 | ||
22 | // miniatures des photos | ||
23 | |||
24 | public function upload() | 27 | public function upload() |
25 | { | 28 | { |
26 | // traitement et enregistrement de l'image | 29 | // traitement et enregistrement de l'image |
@@ -28,14 +31,14 @@ class Image | |||
28 | { | 31 | { |
29 | if ($_FILES['upload']['size'] <= self::MAX_WEIGHT) | 32 | if ($_FILES['upload']['size'] <= self::MAX_WEIGHT) |
30 | { | 33 | { |
31 | $infos = pathinfo($_FILES['upload']['name']); | 34 | $this->pathInfos = pathinfo($_FILES['upload']['name']); |
32 | $extension = $infos['extension']; | 35 | $extension = $this->pathInfos['extension']; |
33 | $extautorisées = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff'); | 36 | $extautorisées = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff'); |
34 | // on prend la même liste que celle côté javascript, le SVG est bloqué pour raison de sécurité (javascript à l'intérieur) | 37 | // on prend la même liste que celle côté javascript, le SVG est bloqué pour raison de sécurité (javascript à l'intérieur) |
35 | if (in_array($extension, $extautorisées)) | 38 | if (in_array($extension, $extautorisées)) |
36 | { | 39 | { |
37 | move_uploaded_file($_FILES['upload']['tmp_name'], 'data/' . $this->page . '/images/' . $_FILES['upload']['name']); | 40 | move_uploaded_file($_FILES['upload']['tmp_name'], $this->path . $_FILES['upload']['name']); |
38 | chmod('data/' . $this->page . '/images/' . $_FILES['upload']['name'], 0666); | 41 | chmod($this->path . $_FILES['upload']['name'], 0666); |
39 | } | 42 | } |
40 | else{$this->erreur = 'mauvais format, veuillez utiliser une image comportant un de ces formats: jpg ou jpeg, png, gif, bmp, webp, tiff<br />le format svg n\'est pas supporté';} | 43 | else{$this->erreur = 'mauvais format, veuillez utiliser une image comportant un de ces formats: jpg ou jpeg, png, gif, bmp, webp, tiff<br />le format svg n\'est pas supporté';} |
41 | } | 44 | } |
@@ -57,4 +60,49 @@ class Image | |||
57 | echo $chemin; | 60 | echo $chemin; |
58 | } | 61 | } |
59 | } | 62 | } |
63 | |||
64 | // miniatures des photos | ||
65 | public function makeThumbnail() | ||
66 | { | ||
67 | if($imageLibrary == 'gd') | ||
68 | { | ||
69 | // des infos sur GD | ||
70 | //print_r(gd_info()); | ||
71 | |||
72 | // cette fonction fonctionne pour tous les formats | ||
73 | $source = imagecreatefromstring(file_get_contents($this->path . $_FILES['upload']['name'])); | ||
74 | var_dump($source); | ||
75 | |||
76 | $nomMiniImage = $this->pathMini . $this->pathInfos['filename'] . '-mini.jpg'; | ||
77 | var_dump($nomMiniImage); | ||
78 | |||
79 | //var_dump($nomMiniImage); | ||
80 | //var_dump(imagesx($image)); | ||
81 | |||
82 | $forme = imagesy($source) / imagesx($source); | ||
83 | var_dump($forme); | ||
84 | |||
85 | if(imagesx($source) > 201) | ||
86 | { | ||
87 | // créer un rectangle noir | ||
88 | $destination = imagecreatetruecolor(201, 201 * $forme); | ||
89 | var_dump($destination); | ||
90 | |||
91 | // sélectionne un rectangle dans l'image source | ||
92 | // et le place dans un rectangle dans la nouvelle | ||
93 | imagecopyresampled($destination, $source, 0, 0, 0, 0, 201, 201 * $forme, imagesx($source), imagesy($source)); | ||
94 | |||
95 | // envoie l'image dans un fichier | ||
96 | imagejpeg($destination, $nomMiniImage); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | imagejpeg($source, $nomMiniImage); | ||
101 | } | ||
102 | } | ||
103 | elseif($imageLibrary == 'imagick') | ||
104 | {} | ||
105 | else | ||
106 | {} | ||
107 | } | ||
60 | } \ No newline at end of file | 108 | } \ No newline at end of file |