summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2023-06-02 01:21:06 +0200
committerpolo <ordipolo@gmx.fr>2023-06-02 01:21:06 +0200
commitce10c0ff1dd0b47bd494ae88ab2eaf6ab354b2b3 (patch)
tree53fd317773354c86e9eff1a19ea9abad81137901 /model
parent082ae3df0b9dd759d56684b0221df62ea171f8ec (diff)
downloadmelaine-ce10c0ff1dd0b47bd494ae88ab2eaf6ab354b2b3.zip
filtre nom des images + reorg code Image
Diffstat (limited to 'model')
-rw-r--r--model/Album.php31
-rw-r--r--model/Article.php2
-rw-r--r--model/Image.php37
3 files changed, 26 insertions, 44 deletions
diff --git a/model/Album.php b/model/Album.php
index d2537f7..801afef 100644
--- a/model/Album.php
+++ b/model/Album.php
@@ -39,25 +39,10 @@ class Album extends Article
39 // fonctions CRUD 39 // fonctions CRUD
40 40
41 // create 41 // create
42 public function createVignette($titre, $annee, $pochette, $pochetteMini) 42 public function createVignetteJSON($titre, $annee, $pochette, $pochetteMini)
43 { 43 {
44 //$this->format = 'json'; 44 //$this->format = 'json';
45 45
46 if($pochette != '')
47 {
48 //echo($pochette); die(); // = nom sans chemin
49
50 // télécharger la pochette
51 require('model/Image.php');
52 $Image = new Image($this->page, $this->folder, false);
53 $Image->upload();
54 $Image->makeThumbnail(201);
55
56 $erreur = $Image->erreur;
57 if(!empty($erreur))
58 {}
59 }
60
61 $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); 46 $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]);
62 //var_dump($albumJSON); die(); 47 //var_dump($albumJSON); die();
63 48
@@ -171,20 +156,6 @@ class Album extends Article
171 $pochette = $albumJSON[2]; 156 $pochette = $albumJSON[2];
172 $pochetteMini = $albumJSON[3]; 157 $pochetteMini = $albumJSON[3];
173 } 158 }
174 else
175 {
176 // télécharger la pochette
177 require('model/Image.php');
178 $Image = new Image($this->page, $this->folder, false);
179 $Image->upload();
180 $Image->makeThumbnail(201);
181 $erreur = $Image->erreur;
182 if(!empty($erreur))
183 {
184 // remettre pochette d'avant
185 //$pochette
186 }
187 }
188 159
189 $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); 160 $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]);
190 161
diff --git a/model/Article.php b/model/Article.php
index 0e8db61..d94ba01 100644
--- a/model/Article.php
+++ b/model/Article.php
@@ -198,8 +198,6 @@ class Article
198 fputs($file, $content); 198 fputs($file, $content);
199 fclose($file); 199 fclose($file);
200 chmod($fileName, 0666); 200 chmod($fileName, 0666);
201
202
203 } 201 }
204 202
205 // read 203 // read
diff --git a/model/Image.php b/model/Image.php
index d71b96a..dbdad62 100644
--- a/model/Image.php
+++ b/model/Image.php
@@ -11,6 +11,8 @@ class Image
11 11
12 public $path; 12 public $path;
13 public $pathMini; 13 public $pathMini;
14 public $FileName; // après sécurisation
15 public $width;
14 public $pathInfos; 16 public $pathInfos;
15 public $erreur; 17 public $erreur;
16 18
@@ -33,20 +35,31 @@ class Image
33 $this->pathMini = 'data/' . $this->folder . '/images-mini/'; 35 $this->pathMini = 'data/' . $this->folder . '/images-mini/';
34 } 36 }
35 37
38 public function setFileName($fileName)
39 {
40 $this->FileName = $fileName;
41 }
42
43 public function setThumbnailWidth($width)
44 {
45 $this->width = $width;
46 }
36 47
37 public function upload() 48 public function upload()
38 { 49 {
39 // traitement et enregistrement de l'image 50 // traitement et enregistrement de l'image
40 if (isset($_FILES['upload']) AND $_FILES['upload']['error'] == 0) // 0 signifie ok 51 if (isset($_FILES['upload']) AND $_FILES['upload']['error'] == 0) // 0 signifie ok
41 { 52 {
42 $this->pathInfos = pathinfo($_FILES['upload']['name']); 53 //$this->pathInfos = pathinfo($_FILES['upload']['name']);
54 $this->pathInfos = pathinfo($this->FileName);
55
43 $extension = $this->pathInfos['extension']; 56 $extension = $this->pathInfos['extension'];
44 $extautorisées = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff'); 57 $extautorisées = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff');
45 // on prend la même liste que celle côté javascript, le SVG est bloqué pour raison de sécurité (javascript à l'intérieur) 58 // on prend la même liste que celle côté javascript, le SVG est bloqué pour raison de sécurité (javascript à l'intérieur)
46 if (in_array($extension, $extautorisées)) 59 if (in_array($extension, $extautorisées))
47 { 60 {
48 move_uploaded_file($_FILES['upload']['tmp_name'], $this->path . $_FILES['upload']['name']); 61 move_uploaded_file($_FILES['upload']['tmp_name'], $this->path . $this->FileName);
49 chmod($this->path . $_FILES['upload']['name'], 0666); 62 chmod($this->path . $this->FileName, 0666);
50 } 63 }
51 else 64 else
52 { 65 {
@@ -63,24 +76,24 @@ class Image
63 if($this->ajax && empty($Image->erreur)) 76 if($this->ajax && empty($Image->erreur))
64 { 77 {
65 // chemin en JSON attendu par l'éditeur 78 // chemin en JSON attendu par l'éditeur
66 $this->reponseAjax = '{"url": "data/' . $this->folder . '/images/' . $_FILES['upload']['name'] . '"}'; 79 $this->reponseAjax = '{"url": "data/' . $this->folder . '/images/' . $this->FileName . '"}';
67 } 80 }
68 } 81 }
69 82
70 // miniatures des photos 83 // miniatures des photos
71 public function makeThumbnail($largeur) 84 public function makeThumbnail()
72 { 85 {
73 global $imageLibrary; 86 global $imageLibrary;
74 87
75 if($imageLibrary == 'imagick') 88 if($imageLibrary == 'imagick')
76 { 89 {
77 $Image = new Imagick($this->path . $_FILES['upload']['name']); 90 $Image = new Imagick($this->path . $this->FileName);
78 91
79 $source = $Image->getImageGeometry(); 92 $source = $Image->getImageGeometry();
80 if($source['width'] > $largeur) 93 if($source['width'] > $this->width)
81 { 94 {
82 // 0 signifie qu'on conserve les proportions 95 // 0 signifie qu'on conserve les proportions
83 $Image->thumbnailImage($largeur, 0); 96 $Image->thumbnailImage($this->width, 0);
84 } 97 }
85 98
86 // écriture dans un fichier 99 // écriture dans un fichier
@@ -89,18 +102,18 @@ class Image
89 elseif($imageLibrary == 'gd') 102 elseif($imageLibrary == 'gd')
90 { 103 {
91 // cette fonction fonctionne pour tous les formats 104 // cette fonction fonctionne pour tous les formats
92 $source = imagecreatefromstring(file_get_contents($this->path . $_FILES['upload']['name'])); 105 $source = imagecreatefromstring(file_get_contents($this->path . $this->FileName));
93 $nomMiniImage = $this->pathMini . $this->pathInfos['filename'] . '-mini.jpg'; 106 $nomMiniImage = $this->pathMini . $this->pathInfos['filename'] . '-mini.jpg';
94 $forme = imagesy($source) / imagesx($source); 107 $forme = imagesy($source) / imagesx($source);
95 108
96 if(imagesx($source) > $largeur) 109 if(imagesx($source) > $this->width)
97 { 110 {
98 // créer un rectangle noir 111 // créer un rectangle noir
99 $destination = imagecreatetruecolor($largeur, $largeur * $forme); 112 $destination = imagecreatetruecolor($this->width, $this->width * $forme);
100 113
101 // sélectionne un rectangle dans l'image source 114 // sélectionne un rectangle dans l'image source
102 // et le place dans un rectangle dans la nouvelle 115 // et le place dans un rectangle dans la nouvelle
103 imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur, $largeur * $forme, imagesx($source), imagesy($source)); 116 imagecopyresampled($destination, $source, 0, 0, 0, 0, $this->width, $this->width * $forme, imagesx($source), imagesy($source));
104 117
105 // envoie l'image dans un fichier 118 // envoie l'image dans un fichier
106 imagejpeg($destination, $nomMiniImage); 119 imagejpeg($destination, $nomMiniImage);