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 | |
| parent | f2c1f219dcd6e25b812d4dbed46f4c0c30541d83 (diff) | |
| download | melaine-9a1fb624fd1089087bd363551ba64f5862d9919f.tar.gz melaine-9a1fb624fd1089087bd363551ba64f5862d9919f.tar.bz2 melaine-9a1fb624fd1089087bd363551ba64f5862d9919f.zip | |
miniatures GD
Diffstat (limited to 'model')
| -rw-r--r-- | model/Album.php | 21 | ||||
| -rw-r--r-- | model/Image.php | 62 |
2 files changed, 68 insertions, 15 deletions
diff --git a/model/Album.php b/model/Album.php index 386a50f..e716a99 100644 --- a/model/Album.php +++ b/model/Album.php | |||
| @@ -21,7 +21,7 @@ class Album extends Article | |||
| 21 | // fonctions CRUD | 21 | // fonctions CRUD |
| 22 | 22 | ||
| 23 | // create | 23 | // create |
| 24 | public function createVignette($titre, $annee, $pochette) | 24 | public function createVignette($titre, $annee, $pochette, $pochetteMini) |
| 25 | { | 25 | { |
| 26 | //$this->format = 'json'; | 26 | //$this->format = 'json'; |
| 27 | 27 | ||
| @@ -33,6 +33,7 @@ class Album extends Article | |||
| 33 | require('model/Image.php'); | 33 | require('model/Image.php'); |
| 34 | $Image = new Image(false); | 34 | $Image = new Image(false); |
| 35 | $Image->upload(); | 35 | $Image->upload(); |
| 36 | $Image->makeThumbnail(); | ||
| 36 | 37 | ||
| 37 | $erreur = $Image->erreur; | 38 | $erreur = $Image->erreur; |
| 38 | if(!empty($erreur)) | 39 | if(!empty($erreur)) |
| @@ -40,7 +41,7 @@ class Album extends Article | |||
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | // encodage avec un tableau simple | 43 | // encodage avec un tableau simple |
| 43 | $albumJSON = json_encode([$titre, $annee, $pochette]); | 44 | $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); |
| 44 | //var_dump($albumJSON); die(); | 45 | //var_dump($albumJSON); die(); |
| 45 | 46 | ||
| 46 | // encodage avec un tableau associatif | 47 | // encodage avec un tableau associatif |
| @@ -66,15 +67,13 @@ class Album extends Article | |||
| 66 | for($i = 0; $i < $this->fileListCount; $i++) | 67 | for($i = 0; $i < $this->fileListCount; $i++) |
| 67 | { | 68 | { |
| 68 | // ajout du JSON | 69 | // ajout du JSON |
| 69 | /*$content = file_get_contents($this->fileList[$i]['fileName']); | ||
| 70 | $content = json_decode($content, true);*/ | ||
| 71 | $content = json_decode($this->fileList[$i]['content'], true); | 70 | $content = json_decode($this->fileList[$i]['content'], true); |
| 72 | //var_dump($content); die(); | ||
| 73 | 71 | ||
| 74 | // lecture de $content étant un tableau simple | 72 | // lecture de $content étant un tableau simple |
| 75 | $this->fileList[$i]['titre'] = $content[0]; | 73 | $this->fileList[$i]['titre'] = $content[0]; |
| 76 | $this->fileList[$i]['annee'] = $content[1]; | 74 | $this->fileList[$i]['annee'] = $content[1]; |
| 77 | $this->fileList[$i]['pochette'] = $content[2]; | 75 | $this->fileList[$i]['pochette'] = $content[2]; |
| 76 | $this->fileList[$i]['pochetteMini'] = $content[3]; | ||
| 78 | 77 | ||
| 79 | // ajout du HTML si il existe | 78 | // ajout du HTML si il existe |
| 80 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) | 79 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) |
| @@ -107,6 +106,7 @@ class Album extends Article | |||
| 107 | $this->oneAlbum['titre'] = $content[0]; | 106 | $this->oneAlbum['titre'] = $content[0]; |
| 108 | $this->oneAlbum['annee'] = $content[1]; | 107 | $this->oneAlbum['annee'] = $content[1]; |
| 109 | $this->oneAlbum['pochette'] = $content[2]; | 108 | $this->oneAlbum['pochette'] = $content[2]; |
| 109 | $this->oneAlbum['pochetteMini'] = $content[3]; | ||
| 110 | 110 | ||
| 111 | // html | 111 | // html |
| 112 | $this->format = 'html'; | 112 | $this->format = 'html'; |
| @@ -138,14 +138,18 @@ class Album extends Article | |||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | // update | 140 | // update |
| 141 | public function updateVignetteJSON($titre, $annee, $pochette) | 141 | public function updateVignetteJSON($titre, $annee, $pochette, $pochetteMini) |
| 142 | { | 142 | { |
| 143 | // garder l'ancienne image | 143 | // garder l'image si aucune n'est sélectionnée |
| 144 | // (on ne peut pas préremplir un <input type="file">) | ||
| 144 | $albumJSON = self::getVignetteJSON(); | 145 | $albumJSON = self::getVignetteJSON(); |
| 146 | /*var_dump($pochette); var_dump($pochetteMini); | ||
| 147 | var_dump($albumJSON); die();*/ | ||
| 145 | 148 | ||
| 146 | if($pochette == '') | 149 | if($pochette == '') |
| 147 | { | 150 | { |
| 148 | $pochette = $albumJSON[2]; | 151 | $pochette = $albumJSON[2]; |
| 152 | $pochetteMini = $albumJSON[3]; | ||
| 149 | } | 153 | } |
| 150 | else | 154 | else |
| 151 | { | 155 | { |
| @@ -153,6 +157,7 @@ class Album extends Article | |||
| 153 | require('model/Image.php'); | 157 | require('model/Image.php'); |
| 154 | $Image = new Image(false); | 158 | $Image = new Image(false); |
| 155 | $Image->upload(); | 159 | $Image->upload(); |
| 160 | $Image->makeThumbnail(); | ||
| 156 | $erreur = $Image->erreur; | 161 | $erreur = $Image->erreur; |
| 157 | if(!empty($erreur)) | 162 | if(!empty($erreur)) |
| 158 | { | 163 | { |
| @@ -161,7 +166,7 @@ class Album extends Article | |||
| 161 | } | 166 | } |
| 162 | } | 167 | } |
| 163 | 168 | ||
| 164 | $albumJSON = json_encode([$titre, $annee, $pochette]); | 169 | $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); |
| 165 | 170 | ||
| 166 | // écriture | 171 | // écriture |
| 167 | $nom_fichier = 'data/discographie/json/' . $this->albumCode . '.json'; | 172 | $nom_fichier = 'data/discographie/json/' . $this->albumCode . '.json'; |
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 |
