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