[SPIP] ~maj v3.0.14-->v3.0.17
[ptitvelo/web/www.git] / www / ecrire / inc / filtres_images_lib_mini.php
1 <?php
2
3 /* *************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 /**
14 * Ce fichier contient les fonctions utilisées
15 * par les fonctions-filtres de traitement d'image.
16 *
17 * @package SPIP\image
18 */
19
20
21 if (!defined('_ECRIRE_INC_VERSION')) return;
22 include_spip('inc/filtres'); // par precaution
23 include_spip('inc/filtres_images_mini'); // par precaution
24
25 /**
26 * Transforme une couleur vectorielle R,G,B en hexa (par exemple pour usage css)
27 *
28 * @param int $red
29 * Valeur du rouge de 0 à 255.
30 * @param int $green
31 * Valeur du vert de 0 à 255.
32 * @param int $blue
33 * Valeur du bleu de 0 à 255.
34 * @return string
35 * le code de la couleur en hexadécimal.
36 */
37 function _couleur_dec_to_hex($red, $green, $blue) {
38 $red = dechex($red);
39 $green = dechex($green);
40 $blue = dechex($blue);
41
42 if (strlen($red) == 1) $red = "0".$red;
43 if (strlen($green) == 1) $green = "0".$green;
44 if (strlen($blue) == 1) $blue = "0".$blue;
45
46 return "$red$green$blue";
47 }
48
49 /**
50 * Transforme une couleur hexa en vectorielle R,G,B
51 *
52 * @param string $couleur
53 * Code couleur en hexa (#000000 à #FFFFFF).
54 * @return array
55 * Un tableau des 3 éléments : rouge, vert, bleu.
56 */
57 function _couleur_hex_to_dec($couleur) {
58 $couleur = couleur_html_to_hex($couleur);
59 $couleur = preg_replace(",^#,","",$couleur);
60 $retour["red"] = hexdec(substr($couleur, 0, 2));
61 $retour["green"] = hexdec(substr($couleur, 2, 2));
62 $retour["blue"] = hexdec(substr($couleur, 4, 2));
63
64 return $retour;
65 }
66
67
68 /**
69 * Donne un statut au fichier-image intermédiaire servant au traitement d'image
70 * selon qu'il doit être gravé (fichier .src) ou pas.
71 * Un appel php direct aux fonctions de filtre d'image produira ainsi une image
72 * permanente (gravée) ; un appel généré par le compilateur via
73 * filtrer('image_xx, ...) effacera automatiquement le fichier-image temporaire.
74 *
75 * @param bool|string $stat
76 * true, false ou le statut déjà défini si traitements enchaînés.
77 * @return bool
78 * true si il faut supprimer le fichier temporaire ; false sinon.
79 */
80 function statut_effacer_images_temporaires($stat){
81 static $statut = false; // par defaut on grave toute les images
82 if ($stat==='get') return $statut;
83 $statut = $stat?true:false;
84 }
85
86
87 /**
88 * Fonctions de traitement d'image
89 * Uniquement pour GD2.
90 *
91 * @param string $img
92 * Un tag html <img src=... />.
93 * @param string $effet
94 * Les nom et paramètres de l'effet à apporter sur l'image
95 * (par exemple : reduire-300-200).
96 * @param bool|string $forcer_format
97 * Un nom d'extension spécifique demandé (par exemple : jpg, png, txt...
98 * par défaut false : GD se débrouille seule).
99 * @param array $fonction_creation
100 * Un tableau à 2 éléments. Le premier (string) indique le nom du
101 * filtre de traitement demandé (par exemple : image_reduire) ; le
102 * second (array) est lui-même un tableau reprenant la valeur de $img
103 * et chacun des paramètres passés au filtre.
104 * @param bool $find_in_path
105 * false (par défaut) indique que l'on travaille sur un fichier
106 * temporaire (.src) ; true, sur un fichier définitif déjà existant.
107 * @return bool|string|array
108 * false si pas de tag <img,
109 * si l'extension n'existe pas,
110 * si le fichier source n'existe pas,
111 * si les dimensions de la source ne sont pas accessibles,
112 * si le fichier temporaire n'existe pas,
113 * si la fonction _imagecreatefrom{extension} n'existe pas ;
114 * "" (chaîne vide) si le fichier source est distant et n'a pas
115 * réussi à être copié sur le serveur ;
116 * l'appel à la fonction pipeline image_preparer_filtre.
117 */
118 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = NULL, $find_in_path = false) {
119 static $images_recalcul = array();
120 if (strlen($img)==0) return false;
121
122 $source = trim(extraire_attribut($img, 'src'));
123 if (strlen($source) < 1){
124 $source = $img;
125 $img = "<img src='$source' />";
126 }
127 # gerer img src="data:....base64"
128 else if (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
129 $local = sous_repertoire(_DIR_VAR,'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
130 if (!file_exists($local)) {
131 ecrire_fichier($local, base64_decode($regs[2]));
132 }
133 $source = $local;
134 $img = inserer_attribut($img, 'src', $source);
135 # eviter les mauvaises surprises lors de conversions de format
136 $img = inserer_attribut($img, 'width', '');
137 $img = inserer_attribut($img, 'height', '');
138 }
139
140 // les protocoles web prennent au moins 3 lettres
141 if (preg_match(';^(\w{3,7}://);', $source)){
142 include_spip('inc/distant');
143 $fichier = _DIR_RACINE . copie_locale($source);
144 if (!$fichier) return "";
145 } else {
146 // enlever le timestamp eventuel
147 $source=preg_replace(',[?][0-9]+$,','',$source);
148 $fichier = $source;
149 }
150
151 $terminaison_dest = "";
152 if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $fichier, $regs)) {
153 $terminaison = strtolower($regs[1]);
154 $terminaison_dest = $terminaison;
155
156 if ($terminaison == "gif") $terminaison_dest = "png";
157 }
158 if ($forcer_format!==false) $terminaison_dest = $forcer_format;
159
160 if (!$terminaison_dest) return false;
161
162 $term_fonction = $terminaison;
163 if ($term_fonction == "jpg") $term_fonction = "jpeg";
164
165 $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
166 $fichier_dest = $nom_fichier;
167 if (($find_in_path AND $f=find_in_path($fichier) AND $fichier=$f)
168 OR @file_exists($f = $fichier)){
169 // on passe la balise img a taille image qui exraira les attributs si possible
170 // au lieu de faire un acces disque sur le fichier
171 list ($ret["hauteur"],$ret["largeur"]) = taille_image($find_in_path?$f:$img);
172 $date_src = @filemtime($f);
173 }
174 elseif (@file_exists($f = "$fichier.src")
175 AND lire_fichier($f,$valeurs)
176 AND $valeurs=unserialize($valeurs)
177 AND isset($valeurs["hauteur_dest"])
178 AND isset($valeurs["largeur_dest"])) {
179 $ret["hauteur"] = $valeurs["hauteur_dest"];
180 $ret["largeur"] = $valeurs["largeur_dest"];
181 $date_src = $valeurs["date"];
182 }
183 // pas de fichier source par la
184 else
185 return false;
186
187 // pas de taille mesurable
188 if (!($ret["hauteur"] OR $ret["largeur"]))
189 return false;
190
191
192 // cas general :
193 // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
194 // cas particulier de reduire :
195 // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
196 $cache = "cache-gd2";
197 if (substr($effet,0,7)=='reduire') {
198 list(,$maxWidth,$maxHeight) = explode('-',$effet);
199 list ($destWidth,$destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
200 $ret['largeur_dest'] = $destWidth;
201 $ret['hauteur_dest'] = $destHeight;
202 $effet = "L{$destWidth}xH$destHeight";
203 $cache = "cache-vignettes";
204 $fichier_dest = basename($fichier_dest);
205 if (($ret['largeur']<=$maxWidth)&&($ret['hauteur']<=$maxHeight)){
206 // on garde la terminaison initiale car image simplement copiee
207 // et on postfixe son nom avec un md5 du path
208 $terminaison_dest = $terminaison;
209 $fichier_dest .= '-'.substr(md5("$fichier"),0,5);
210 }
211 else
212 $fichier_dest .= '-'.substr(md5("$fichier-$effet"),0,5);
213 $cache = sous_repertoire(_DIR_VAR, $cache);
214 $cache = sous_repertoire($cache, $effet);
215 # cherche un cache existant
216 /*foreach (array('gif','jpg','png') as $fmt)
217 if (@file_exists($cache . $fichier_dest . '.' . $fmt)) {
218 $terminaison_dest = $fmt;
219 }*/
220 }
221 else {
222 $fichier_dest = md5("$fichier-$effet");
223 $cache = sous_repertoire(_DIR_VAR, $cache);
224 }
225
226 $fichier_dest = $cache . $fichier_dest . "." .$terminaison_dest;
227
228 $GLOBALS["images_calculees"][] = $fichier_dest;
229
230 $creer = true;
231 // si recalcul des images demande, recalculer chaque image une fois
232 if (defined('_VAR_IMAGES') AND _VAR_IMAGES AND !isset($images_recalcul[$fichier_dest])){
233 $images_recalcul[$fichier_dest] = true;
234 }
235 else {
236 if (@file_exists($f = $fichier_dest)){
237 if (filemtime($f)>=$date_src)
238 $creer = false;
239 }
240 else if (@file_exists($f = "$fichier_dest.src")
241 AND lire_fichier($f,$valeurs)
242 AND $valeurs=unserialize($valeurs)
243 AND $valeurs["date"]>=$date_src)
244 $creer = false;
245 }
246 if ($creer) {
247 if (!@file_exists($fichier)) {
248 if (!@file_exists("$fichier.src")) {
249 spip_log("Image absente : $fichier");
250 return false;
251 }
252 # on reconstruit l'image source absente a partir de la chaine des .src
253 reconstruire_image_intermediaire($fichier);
254 }
255 }
256
257 if ($creer)
258 spip_log("filtre image ".($fonction_creation?reset($fonction_creation):'')."[$effet] sur $fichier","images"._LOG_DEBUG);
259
260 // TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f
261 $ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
262 $ret["fichier"] = $fichier;
263 $ret["fonction_image"] = "_image_image".$terminaison_dest;
264 $ret["fichier_dest"] = $fichier_dest;
265 $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
266 $ret["format_dest"] = $terminaison_dest;
267 $ret["date_src"] = $date_src;
268 $ret["creer"] = $creer;
269 $ret["class"] = extraire_attribut($img, 'class');
270 $ret["alt"] = extraire_attribut($img, 'alt');
271 $ret["style"] = extraire_attribut($img, 'style');
272 $ret["tag"] = $img;
273 if ($fonction_creation){
274 $ret["reconstruction"] = $fonction_creation;
275 # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
276 # cas de image_reduire qui finalement ne reduit pas l'image source
277 # ca evite d'essayer de le creer au prochain hit si il n'est pas la
278 #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
279 }
280
281 $ret = pipeline('image_preparer_filtre',array(
282 'args'=>array(
283 'img'=>$img,
284 'effet'=>$effet,
285 'forcer_format'=>$forcer_format,
286 'fonction_creation'=>$fonction_creation,
287 'find_in_path'=>$find_in_path,
288 ),
289 'data'=>$ret)
290 );
291
292 // une globale pour le debug en cas de crash memoire
293 $GLOBALS["derniere_image_calculee"] = $ret;
294
295 if (!function_exists($ret["fonction_imagecreatefrom"])) return false;
296 return $ret;
297 }
298
299 /**
300 * Crée une image depuis un fichier ou une URL
301 * Utilise les fonctions spécifiques GD.
302 *
303 * @param string $filename
304 * Le path vers l'image à traiter (par exemple : IMG/distant/jpg/image.jpg
305 * ou local/cache-vignettes/L180xH51/image.jpg).
306 * @return ressource
307 * Une ressource de type Image GD.
308 */
309 function _imagecreatefromjpeg($filename){
310 $img = @imagecreatefromjpeg($filename);
311 if (!$img) {
312 spip_log("Erreur lecture imagecreatefromjpeg $filename",_LOG_CRITIQUE);
313 erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
314 $img = imagecreate(10,10);
315 }
316 return $img;
317 }
318
319 /**
320 * Crée une image depuis un fichier ou une URL
321 * Utilise les fonctions spécifiques GD.
322 *
323 * @param string $filename
324 * Le path vers l'image à traiter (par exemple : IMG/distant/png/image.png
325 * ou local/cache-vignettes/L180xH51/image.png).
326 * @return ressource
327 * Une ressource de type Image GD.
328 */
329 function _imagecreatefrompng($filename){
330 $img = @imagecreatefrompng($filename);
331 if (!$img) {
332 spip_log("Erreur lecture imagecreatefrompng $filename",_LOG_CRITIQUE);
333 erreur_squelette("Erreur lecture imagecreatefrompng $filename");
334 $img = imagecreate(10,10);
335 }
336 return $img;
337 }
338
339 /**
340 * Crée une image depuis un fichier ou une URL
341 * Utilise les fonctions spécifiques GD.
342 *
343 * @param string $filename
344 * Le path vers l'image à traiter (par exemple : IMG/distant/gif/image.gif
345 * ou local/cache-vignettes/L180xH51/image.gif).
346 * @return ressource
347 * Une ressource de type Image GD.
348 */
349 function _imagecreatefromgif($filename){
350 $img = @imagecreatefromgif($filename);
351 if (!$img) {
352 spip_log("Erreur lecture imagecreatefromgif $filename",_LOG_CRITIQUE);
353 erreur_squelette("Erreur lecture imagecreatefromgif $filename");
354 $img = imagecreate(10,10);
355 }
356 return $img;
357 }
358
359 /**
360 * Affiche ou sauvegarde une image au format PNG
361 * Utilise les fonctions spécifiques GD.
362 *
363 * @param ressource $img
364 * Une ressource de type Image GD.
365 * @param string $fichier
366 * Le path vers l'image (ex : local/cache-vignettes/L180xH51/image.png).
367 * @return bool
368 * false si l'image créée a une largeur nulle ou n'existe pas ;
369 * true si une image est bien retournée.
370 */
371 function _image_imagepng($img, $fichier) {
372 if (!function_exists('imagepng')) return false;
373 $tmp = $fichier.".tmp";
374 $ret = imagepng($img,$tmp);
375
376 if(file_exists($tmp)){
377 $taille_test = getimagesize($tmp);
378 if ($taille_test[0] < 1) return false;
379
380 spip_unlink($fichier); // le fichier peut deja exister
381 @rename($tmp, $fichier);
382 return $ret;
383 }
384 return false;
385 }
386
387 /**
388 * Affiche ou sauvegarde une image au format GIF
389 * Utilise les fonctions spécifiques GD.
390 *
391 * @param ressource $img
392 * Une ressource de type Image GD.
393 * @param string $fichier
394 * Le path vers l'image (ex : local/cache-vignettes/L180xH51/image.gif).
395 * @return bool
396 * false si l'image créée a une largeur nulle ou n'existe pas;
397 * true si une image est bien retournée.
398 */
399 function _image_imagegif($img,$fichier) {
400 if (!function_exists('imagegif')) return false;
401 $tmp = $fichier.".tmp";
402 $ret = imagegif($img,$tmp);
403
404 if(file_exists($tmp)){
405 $taille_test = getimagesize($tmp);
406 if ($taille_test[0] < 1) return false;
407
408 spip_unlink($fichier); // le fichier peut deja exister
409 @rename($tmp, $fichier);
410 return $ret;
411 }
412 return false;
413 }
414
415 /**
416 * Affiche ou sauvegarde une image au format JPG
417 * Utilise les fonctions spécifiques GD.
418 *
419 * @param ressource $img
420 * Une ressource de type Image GD.
421 * @param string $fichier
422 * Le path vers l'image (ex : local/cache-vignettes/L180xH51/image.jpg).
423 * @param int $qualite
424 * Le niveau de qualité du fichier résultant : de 0 (pire qualité, petit
425 * fichier) à 100 (meilleure qualité, gros fichier). Par défaut, prend la
426 * valeur (85) de la constante _IMG_GD_QUALITE (modifiable depuis
427 * mes_options.php).
428 * @return bool
429 * false si l'image créée a une largeur nulle ou n'existe pas ;
430 * true si une image est bien retournée.
431 */
432 function _image_imagejpg($img,$fichier,$qualite=_IMG_GD_QUALITE) {
433 if (!function_exists('imagejpeg')) return false;
434 $tmp = $fichier.".tmp";
435 $ret = imagejpeg($img,$tmp, $qualite);
436
437 if(file_exists($tmp)){
438 $taille_test = getimagesize($tmp);
439 if ($taille_test[0] < 1) return false;
440
441 spip_unlink($fichier); // le fichier peut deja exister
442 @rename($tmp, $fichier);
443 return $ret;
444 }
445 return false;
446 }
447
448 /**
449 * Crée un fichier-image au format ICO
450 * Utilise les fonctions de la classe phpthumb_functions.
451 *
452 * @param ressource $img
453 * Une ressource de type Image GD.
454 * @param string $fichier
455 * Le path vers l'image (ex : local/cache-vignettes/L180xH51/image.jpg).
456 * @return bool
457 * true si le fichier a bien été créé ; false sinon.
458 */
459 function _image_imageico($img, $fichier) {
460 $gd_image_array = array($img);
461
462 return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
463 }
464
465 /**
466 * Finalise le traitement GD
467 * Crée un fichier_image temporaire .src ou vérifie que le fichier_image
468 * définitif a bien été créé.
469 *
470 * @param ressource $img
471 * Une ressource de type Image GD.
472 * @param array $valeurs
473 * Un tableau des informations (tailles, traitement, path...) accompagnant
474 * l'image.
475 * @param int $qualite
476 * N'est utilisé que pour les images jpg.
477 * Le niveau de qualité du fichier résultant : de 0 (pire qualité, petit
478 * fichier) à 100 (meilleure qualité, gros fichier). Par défaut, prend la
479 * valeur (85) de la constante _IMG_GD_QUALITE (modifiable depuis
480 * mes_options.php).
481 * @return bool
482 * true si le traitement GD s'est bien finalisé ;
483 * false sinon.
484 */
485 function _image_gd_output($img,$valeurs, $qualite=_IMG_GD_QUALITE){
486 $fonction = "_image_image".$valeurs['format_dest'];
487 $ret = false;
488 #un flag pour reperer les images gravees
489 $lock =
490 !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
491 OR (@file_exists($valeurs['fichier_dest']) AND !@file_exists($valeurs['fichier_dest'].'.src'));
492 if (
493 function_exists($fonction)
494 && ($ret = $fonction($img,$valeurs['fichier_dest'],$qualite)) # on a reussi a creer l'image
495 && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
496 && !$lock
497 )
498 if (@file_exists($valeurs['fichier_dest'])){
499 // dans tous les cas mettre a jour la taille de l'image finale
500 list ($valeurs["hauteur_dest"],$valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
501 $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
502 ecrire_fichier($valeurs['fichier_dest'].'.src',serialize($valeurs),true);
503 }
504 return $ret;
505 }
506
507 // http://doc.spip.org/@reconstruire_image_intermediaire
508 function reconstruire_image_intermediaire($fichier_manquant){
509 $reconstruire = array();
510 $fichier = $fichier_manquant;
511 while (
512 !@file_exists($fichier)
513 AND lire_fichier($src = "$fichier.src",$source)
514 AND $valeurs=unserialize($source)
515 AND ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
516 ) {
517 spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
518 $reconstruire[] = $valeurs['reconstruction'];
519 }
520 while (count($reconstruire)){
521 $r = array_pop($reconstruire);
522 $fonction = $r[0];
523 $args = $r[1];
524 call_user_func_array($fonction, $args);
525 }
526 // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
527 // mais l'on peut nettoyer les miettes de sa creation
528 ramasse_miettes($fichier_manquant);
529 }
530
531 // http://doc.spip.org/@ramasse_miettes
532 function ramasse_miettes($fichier){
533 if (!lire_fichier($src = "$fichier.src",$source)
534 OR !$valeurs=unserialize($source)) return;
535 spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
536 while (
537 ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
538 AND (substr($fichier,0,strlen(_DIR_VAR))==_DIR_VAR) # et est dans local
539 AND (lire_fichier($src = "$fichier.src",$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
540 AND ($valeurs=unserialize($source)) # et valide
541 ) {
542 # on efface le fichier
543 spip_unlink($fichier);
544 # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
545 #spip_unlink($src);
546 }
547 }
548
549 // http://doc.spip.org/@image_graver
550 function image_graver($img){
551 // appeler le filtre post_image_filtrer qui permet de faire
552 // des traitements auto a la fin d'une serie de filtres
553 $img = pipeline('post_image_filtrer',$img);
554
555 $fichier = extraire_attribut($img, 'src');
556 if (($p=strpos($fichier,'?'))!==FALSE)
557 $fichier=substr($fichier,0,$p);
558 if (strlen($fichier) < 1)
559 $fichier = $img;
560 # si jamais le fichier final n'a pas ete calcule car suppose temporaire
561 if (!@file_exists($fichier))
562 reconstruire_image_intermediaire($fichier);
563 ramasse_miettes($fichier);
564 return $img; // on ne change rien
565 }
566
567 // Transforme une image a palette indexee (256 couleurs max) en "vraies" couleurs RGB
568 // Existe seulement pour compatibilite avec PHP < 5.5
569 // http://doc.spip.org/@imagepalettetotruecolor
570 if (!function_exists("imagepalettetotruecolor")) {
571 function imagepalettetotruecolor(&$img) {
572 if ($img AND !imageistruecolor($img) AND function_exists('imagecreatetruecolor')) {
573 $w = imagesx($img);
574 $h = imagesy($img);
575 $img1 = imagecreatetruecolor($w,$h);
576 //Conserver la transparence si possible
577 if(function_exists('ImageCopyResampled')) {
578 if (function_exists("imageAntiAlias")) imageAntiAlias($img1,true);
579 @imagealphablending($img1, false);
580 @imagesavealpha($img1,true);
581 @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
582 } else {
583 imagecopy($img1,$img,0,0,0,0,$w,$h);
584 }
585
586 $img = $img1;
587 }
588 }
589 }
590
591 // http://doc.spip.org/@image_tag_changer_taille
592 function _image_tag_changer_taille($tag,$width,$height,$style=false){
593 if ($style===false) $style = extraire_attribut($tag,'style');
594 // enlever le width et height du style
595 $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims","",$style);
596 if ($style AND $style{0}==';') $style=substr($style,1);
597 // mettre des attributs de width et height sur les images,
598 // ca accelere le rendu du navigateur
599 // ca permet aux navigateurs de reserver la bonne taille
600 // quand on a desactive l'affichage des images.
601 $tag = inserer_attribut($tag,'width',$width);
602 $tag = inserer_attribut($tag,'height',$height);
603
604 // Ancien style inline pour IE6 mais qui casse la possibilité de surcharger en CSS
605 //$style = "height:".$height."px;width:".$width."px;".$style;
606
607 // attributs deprecies. Transformer en CSS
608 if ($espace = extraire_attribut($tag, 'hspace')){
609 $style = "margin:${espace}px;".$style;
610 $tag = inserer_attribut($tag,'hspace','');
611 }
612 $tag = inserer_attribut($tag,'style',$style, true, $style ? false : true);
613 return $tag;
614 }
615
616 // function d'ecriture du de la balise img en sortie des filtre image
617 // reprend le tag initial et surcharge les tags modifies
618 function _image_ecrire_tag($valeurs,$surcharge=array()){
619 $valeurs = pipeline('image_ecrire_tag_preparer',$valeurs);
620
621 $tag = str_replace(">","/>",str_replace("/>",">",$valeurs['tag'])); // fermer les tags img pas bien fermes;
622
623 // le style
624 $style = $valeurs['style'];
625 if (isset($surcharge['style'])){
626 $style = $surcharge['style'];
627 unset($surcharge['style']);
628 }
629
630 // traiter specifiquement la largeur et la hauteur
631 $width = $valeurs['largeur'];
632 if (isset($surcharge['width'])){
633 $width = $surcharge['width'];
634 unset($surcharge['width']);
635 }
636 $height = $valeurs['hauteur'];
637 if (isset($surcharge['height'])){
638 $height = $surcharge['height'];
639 unset($surcharge['height']);
640 }
641
642 $tag = _image_tag_changer_taille($tag,$width,$height,$style);
643 // traiter specifiquement le src qui peut etre repris dans un onmouseout
644 // on remplace toute les ref a src dans le tag
645 $src = extraire_attribut($tag,'src');
646 if (isset($surcharge['src'])){
647 $tag = str_replace($src,$surcharge['src'],$tag);
648 // si il y a des & dans src, alors ils peuvent provenir d'un &amp
649 // pas garanti comme methode, mais mieux que rien
650 if (strpos($src,'&') !== false)
651 $tag = str_replace(str_replace("&","&amp;",$src),$surcharge['src'],$tag);
652 $src = $surcharge['src'];
653 unset($surcharge['src']);
654 }
655
656 $class = $valeurs['class'];
657 if (isset($surcharge['class'])){
658 $class = $surcharge['class'];
659 unset($surcharge['class']);
660 }
661 if(strlen($class))
662 $tag = inserer_attribut($tag,'class',$class);
663
664 if (count($surcharge))
665 foreach($surcharge as $attribut=>$valeur)
666 $tag = inserer_attribut($tag,$attribut,$valeur);
667
668 $tag = pipeline('image_ecrire_tag_finir',
669 array(
670 'args' => array(
671 'valeurs' => $valeurs,
672 'surcharge' => $surcharge,
673 ),
674 'data' => $tag
675 )
676 );
677
678 return $tag;
679 }
680
681 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process='AUTO', $force=false, $test_cache_only = false) {
682 // ordre de preference des formats graphiques pour creer les vignettes
683 // le premier format disponible, selon la methode demandee, est utilise
684 $image = $valeurs['fichier'];
685 $format = $valeurs['format_source'];
686 $destdir = dirname($valeurs['fichier_dest']);
687 $destfile = basename($valeurs['fichier_dest'],".".$valeurs["format_dest"]);
688
689 $format_sortie = $valeurs['format_dest'];
690
691 // liste des formats qu'on sait lire
692 $img = isset($GLOBALS['meta']['formats_graphiques'])
693 ? (strpos($GLOBALS['meta']['formats_graphiques'], $format)!==false)
694 : false;
695
696 // si le doc n'est pas une image, refuser
697 if (!$force AND !$img) return;
698 $destination = "$destdir/$destfile";
699
700 // chercher un cache
701 $vignette = '';
702 if ($test_cache_only AND !$vignette) return;
703
704 // utiliser le cache ?
705 if (!$test_cache_only)
706 if ($force OR !$vignette OR (@filemtime($vignette) < @filemtime($image))) {
707
708 $creation = true;
709 // calculer la taille
710 if (($srcWidth=$valeurs['largeur']) && ($srcHeight=$valeurs['hauteur'])){
711 if (!($destWidth=$valeurs['largeur_dest']) || !($destHeight=$valeurs['hauteur_dest']))
712 list ($destWidth,$destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
713 }
714 elseif ($process == 'convert' OR $process == 'imagick') {
715 $destWidth = $maxWidth;
716 $destHeight = $maxHeight;
717 } else {
718 spip_log("echec $process sur $image");
719 return;
720 }
721
722 // Si l'image est de la taille demandee (ou plus petite), simplement
723 // la retourner
724 if ($srcWidth
725 AND $srcWidth <= $maxWidth AND $srcHeight <= $maxHeight) {
726 $vignette = $destination.'.'.$format;
727 @copy($image, $vignette);
728 }
729 // imagemagick en ligne de commande
730 else if ($process == 'convert') {
731 define('_CONVERT_COMMAND', 'convert');
732 define ('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
733 $vignette = $destination.".".$format_sortie;
734 $commande = str_replace(
735 array('%x', '%y', '%src', '%dest'),
736 array(
737 $destWidth,
738 $destHeight,
739 escapeshellcmd($image),
740 escapeshellcmd($vignette)
741 ),
742 _RESIZE_COMMAND);
743 spip_log($commande);
744 exec($commande);
745 if (!@file_exists($vignette)) {
746 spip_log("echec convert sur $vignette");
747 return; // echec commande
748 }
749 }
750 else
751 // imagick (php4-imagemagick)
752 if ($process == 'imagick') {
753
754 $vignette = "$destination.".$format_sortie;
755
756 $imagick = new Imagick();
757 $imagick->readImage($image);
758 $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, 1 );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
759 $imagick->writeImage($vignette);
760
761 if (!@file_exists($vignette)) {
762 spip_log("echec imagick sur $vignette");
763 return;
764 }
765 }
766 else
767 // netpbm
768 if ($process == "netpbm") {
769 define('_PNMSCALE_COMMAND', 'pnmscale'); // chemin a changer dans mes_options
770 if (_PNMSCALE_COMMAND == '') return;
771 $vignette = $destination.".".$format_sortie;
772 $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
773 if ($format == "jpg") {
774
775 $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
776 exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
777 if (!($s = @filesize($vignette)))
778 spip_unlink($vignette);
779 if (!@file_exists($vignette)) {
780 spip_log("echec netpbm-jpg sur $vignette");
781 return;
782 }
783 } else if ($format == "gif") {
784 $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
785 exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
786 if (!($s = @filesize($vignette)))
787 spip_unlink($vignette);
788 if (!@file_exists($vignette)) {
789 spip_log("echec netpbm-gif sur $vignette");
790 return;
791 }
792 } else if ($format == "png") {
793 $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
794 exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
795 if (!($s = @filesize($vignette)))
796 spip_unlink($vignette);
797 if (!@file_exists($vignette)) {
798 spip_log("echec netpbm-png sur $vignette");
799 return;
800 }
801 }
802 }
803 // gd ou gd2
804 else if ($process == 'gd1' OR $process == 'gd2') {
805 if (_IMG_GD_MAX_PIXELS && $srcWidth*$srcHeight>_IMG_GD_MAX_PIXELS){
806 spip_log("vignette gd1/gd2 impossible : ".$srcWidth*$srcHeight."pixels");
807 return;
808 }
809 $destFormat = $format_sortie;
810 if (!$destFormat) {
811 spip_log("pas de format pour $image");
812 return;
813 }
814
815 $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
816 if (!function_exists($fonction_imagecreatefrom))
817 return '';
818 $srcImage = @$fonction_imagecreatefrom($image);
819 if (!$srcImage) {
820 spip_log("echec gd1/gd2");
821 return;
822 }
823
824 // Initialisation de l'image destination
825 if ($process == 'gd2' AND $destFormat != "gif")
826 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
827 if (!$destImage)
828 $destImage = ImageCreate($destWidth, $destHeight);
829
830 // Recopie de l'image d'origine avec adaptation de la taille
831 $ok = false;
832 if (($process == 'gd2') AND function_exists('ImageCopyResampled')) {
833 if ($format == "gif") {
834 // Si un GIF est transparent,
835 // fabriquer un PNG transparent
836 $transp = imagecolortransparent($srcImage);
837 if ($transp > 0) $destFormat = "png";
838 }
839 if ($destFormat == "png") {
840 // Conserver la transparence
841 if (function_exists("imageAntiAlias")) imageAntiAlias($destImage,true);
842 @imagealphablending($destImage, false);
843 @imagesavealpha($destImage,true);
844 }
845 $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
846 }
847 if (!$ok)
848 $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
849
850 // Sauvegarde de l'image destination
851 $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
852 $valeurs['format_dest'] = $format = $destFormat;
853 _image_gd_output($destImage,$valeurs);
854
855 if ($srcImage)
856 ImageDestroy($srcImage);
857 ImageDestroy($destImage);
858 }
859 }
860 $size = @getimagesize($vignette);
861 // Gaffe: en safe mode, pas d'acces a la vignette,
862 // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
863 if ($size[0] < 1) $size[0] = $destWidth;
864 if ($size[1] < 1) $size[1] = $destHeight;
865
866 $retour['width'] = $largeur = $size[0];
867 $retour['height'] = $hauteur = $size[1];
868
869 $retour['fichier'] = $vignette;
870 $retour['format'] = $format;
871 $retour['date'] = @filemtime($vignette);
872
873 // renvoyer l'image
874 return $retour;
875 }
876
877 // Calculer le ratio
878 // http://doc.spip.org/@image_ratio
879 function _image_ratio ($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
880 $ratioWidth = $srcWidth/$maxWidth;
881 $ratioHeight = $srcHeight/$maxHeight;
882
883 if ($ratioWidth <=1 AND $ratioHeight <=1) {
884 $destWidth = $srcWidth;
885 $destHeight = $srcHeight;
886 } else if ($ratioWidth < $ratioHeight) {
887 $destWidth = $srcWidth/$ratioHeight;
888 $destHeight = $maxHeight;
889 }
890 else {
891 $destWidth = $maxWidth;
892 $destHeight = $srcHeight/$ratioWidth;
893 }
894 return array (ceil($destWidth), ceil($destHeight),
895 max($ratioWidth,$ratioHeight));
896 }
897
898 // Calculer le ratio ajuste sur la plus petite dimension
899 // http://doc.spip.org/@ratio_passe_partout
900 function ratio_passe_partout ($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
901 $ratioWidth = $srcWidth/$maxWidth;
902 $ratioHeight = $srcHeight/$maxHeight;
903
904 if ($ratioWidth <=1 AND $ratioHeight <=1) {
905 $destWidth = $srcWidth;
906 $destHeight = $srcHeight;
907 } else if ($ratioWidth > $ratioHeight) {
908 $destWidth = $srcWidth/$ratioHeight;
909 $destHeight = $maxHeight;
910 }
911 else {
912 $destWidth = $maxWidth;
913 $destHeight = $srcHeight/$ratioWidth;
914 }
915 return array (ceil($destWidth), ceil($destHeight),
916 min($ratioWidth,$ratioHeight));
917 }
918
919 // http://doc.spip.org/@process_image_reduire
920 function process_image_reduire($fonction,$img,$taille,$taille_y,$force,$cherche_image,$process){
921 $image = false;
922 if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process']))
923 $process = $GLOBALS['meta']['image_process'];
924 # determiner le format de sortie
925 $format_sortie = false; // le choix par defaut sera bon
926 if ($process == "netpbm") $format_sortie = "jpg";
927 else if ($process == 'gd1' OR $process == 'gd2') {
928 $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
929
930 // on verifie que l'extension choisie est bonne (en principe oui)
931 $gd_formats = explode(',',$GLOBALS['meta']["gd_formats"]);
932 if (!in_array($image['format_dest'],$gd_formats)
933 OR ($image['format_dest']=='gif' AND !function_exists('ImageGif'))
934 ) {
935 if ($image['format_source'] == 'jpg')
936 $formats_sortie = array('jpg','png','gif');
937 else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
938 $formats_sortie = array('png','jpg','gif');
939 // Choisir le format destination
940 // - on sauve de preference en JPEG (meilleure compression)
941 // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
942 # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
943 # pas *ecrire*
944 $format_sortie = "";
945 foreach ($formats_sortie as $fmt) {
946 if (in_array($fmt, $gd_formats)) {
947 if ($fmt <> "gif" OR function_exists('ImageGif'))
948 $format_sortie = $fmt;
949 break;
950 }
951 }
952 $image = false;
953 }
954 }
955
956 if (!$image)
957 $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
958
959 if (!$image OR !$image['largeur'] OR !$image['hauteur']){
960 spip_log("image_reduire_src:pas de version locale de $img");
961 // on peut resizer en mode html si on dispose des elements
962 if ($srcw = extraire_attribut($img, 'width')
963 AND $srch = extraire_attribut($img, 'height')) {
964 list($w,$h) = _image_ratio($srcw, $srch, $taille, $taille_y);
965 return _image_tag_changer_taille($img,$w,$h);
966 }
967 // la on n'a pas d'infos sur l'image source... on refile le truc a css
968 // sous la forme style='max-width: NNpx;'
969 return inserer_attribut($img, 'style',
970 "max-width: ${taille}px; max-height: ${taille_y}px");
971 }
972
973 // si l'image est plus petite que la cible retourner une copie cachee de l'image
974 if (($image['largeur']<=$taille)&&($image['hauteur']<=$taille_y)){
975 if ($image['creer']){
976 @copy($image['fichier'], $image['fichier_dest']);
977 }
978 return _image_ecrire_tag($image,array('src'=>$image['fichier_dest']));
979 }
980
981 if ($image['creer']==false && !$force)
982 return _image_ecrire_tag($image,array('src'=>$image['fichier_dest'],'width'=>$image['largeur_dest'],'height'=>$image['hauteur_dest']));
983
984 if (in_array($image["format_source"],array('jpg','gif','png'))){
985 $destWidth = $image['largeur_dest'];
986 $destHeight = $image['hauteur_dest'];
987 $logo = $image['fichier'];
988 $date = $image["date_src"];
989 $preview = _image_creer_vignette($image, $taille, $taille_y,$process,$force);
990
991 if ($preview && $preview['fichier']) {
992 $logo = $preview['fichier'];
993 $destWidth = $preview['width'];
994 $destHeight = $preview['height'];
995 $date = $preview['date'];
996 }
997 // dans l'espace prive mettre un timestamp sur l'adresse
998 // de l'image, de facon a tromper le cache du navigateur
999 // quand on fait supprimer/reuploader un logo
1000 // (pas de filemtime si SAFE MODE)
1001 $date = test_espace_prive() ? ('?'.$date) : '';
1002 return _image_ecrire_tag($image,array('src'=>"$logo$date",'width'=>$destWidth,'height'=>$destHeight));
1003 }
1004 else
1005 # SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1006 return $img;
1007 }
1008
1009 /**
1010 * Produire des fichiers au format .ico
1011 * avec du code recupere de :
1012 * phpThumb() by James Heinrich <info@silisoftware.com>
1013 * available at http://phpthumb.sourceforge.net
1014 *
1015 * Class phpthumb_functions
1016 */
1017 class phpthumb_functions {
1018
1019 /**
1020 * @param ressource $img
1021 * @param int $x
1022 * @param int $y
1023 * @return array|bool
1024 */
1025 public static function GetPixelColor(&$img, $x, $y) {
1026 if (!is_resource($img)) {
1027 return false;
1028 }
1029 return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1030 }
1031
1032 /**
1033 * @param int $number
1034 * @param int $minbytes
1035 * @return string
1036 */
1037 public static function LittleEndian2String($number, $minbytes=1) {
1038 $intstring = '';
1039 while ($number > 0) {
1040 $intstring = $intstring.chr($number & 255);
1041 $number >>= 8;
1042 }
1043 return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1044 }
1045
1046 /**
1047 * @param array $gd_image_array
1048 * @return string
1049 */
1050 public static function GD2ICOstring(&$gd_image_array) {
1051 foreach ($gd_image_array as $key => $gd_image) {
1052
1053 $ImageWidths[$key] = ImageSX($gd_image);
1054 $ImageHeights[$key] = ImageSY($gd_image);
1055 $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1056 $totalcolors[$key] = ImageColorsTotal($gd_image);
1057
1058 $icXOR[$key] = '';
1059 for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1060 for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1061 $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1062 $a = round(255 * ((127 - $argb['alpha']) / 127));
1063 $r = $argb['red'];
1064 $g = $argb['green'];
1065 $b = $argb['blue'];
1066
1067 if ($bpp[$key] == 32) {
1068 $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1069 } elseif ($bpp[$key] == 24) {
1070 $icXOR[$key] .= chr($b).chr($g).chr($r);
1071 }
1072
1073 if ($a < 128) {
1074 @$icANDmask[$key][$y] .= '1';
1075 } else {
1076 @$icANDmask[$key][$y] .= '0';
1077 }
1078 }
1079 // mask bits are 32-bit aligned per scanline
1080 while (strlen($icANDmask[$key][$y]) % 32) {
1081 $icANDmask[$key][$y] .= '0';
1082 }
1083 }
1084 $icAND[$key] = '';
1085 foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1086 for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1087 $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1088 }
1089 }
1090
1091 }
1092
1093 foreach ($gd_image_array as $key => $gd_image) {
1094 $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1095
1096 // BITMAPINFOHEADER - 40 bytes
1097 $BitmapInfoHeader[$key] = '';
1098 $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize;
1099 $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth;
1100 // The biHeight member specifies the combined
1101 // height of the XOR and AND masks.
1102 $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight;
1103 $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes;
1104 $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1105 $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression;
1106 $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage;
1107 $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter;
1108 $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter;
1109 $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed;
1110 $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant;
1111 }
1112
1113
1114 $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0)
1115 $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons)
1116 $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images?
1117
1118 $dwImageOffset = 6 + (count($gd_image_array) * 16);
1119 foreach ($gd_image_array as $key => $gd_image) {
1120 // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
1121
1122 $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image
1123 $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image
1124 $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp)
1125 $icondata .= "\x00"; // bReserved; // Reserved ( must be 0)
1126
1127 $icondata .= "\x01\x00"; // wPlanes; // Color Planes
1128 $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel
1129
1130 $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1131 $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4); // dwBytesInRes; // How many bytes in this resource?
1132
1133 $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4); // dwImageOffset; // Where in the file is this image?
1134 $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1135 $dwImageOffset += strlen($icXOR[$key]);
1136 $dwImageOffset += strlen($icAND[$key]);
1137 }
1138
1139 foreach ($gd_image_array as $key => $gd_image) {
1140 $icondata .= $BitmapInfoHeader[$key];
1141 $icondata .= $icXOR[$key];
1142 $icondata .= $icAND[$key];
1143 }
1144
1145 return $icondata;
1146 }
1147
1148 }
1149
1150 ?>