[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / ecrire / action / tester.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2017 *
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 * Gestion de l'action testant une librairie graphique
15 *
16 * @package SPIP\Core\Configurer
17 */
18
19 if (!defined('_ECRIRE_INC_VERSION')) {
20 return;
21 }
22
23 /**
24 * Tester les capacités du serveur à utiliser une librairie graphique
25 *
26 * L'argument transmis dans la clé `arg` est le type de librairie parmi
27 * gd2, gd1, netpbm, imagick ou convert
28 *
29 * L'action crée une vignette en utilisant la librairie indiquée puis
30 * redirige sur l'image ainsi créée (sinon sur une image d'echec).
31 **/
32 function action_tester_dist() {
33 $arg = _request('arg');
34
35 $gd_formats = array();
36 $gd_formats_read_gif = "";
37 // verifier les formats acceptes par GD
38 if ($arg == "gd1") {
39 // Si GD est installe et php >= 4.0.2
40 if (function_exists('imagetypes')) {
41
42 if (imagetypes() & IMG_GIF) {
43 $gd_formats[] = "gif";
44 } else {
45 # Attention GD sait lire le gif mais pas forcement l'ecrire
46 if (function_exists('ImageCreateFromGIF')) {
47 $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . "test.gif");
48 if ($srcImage) {
49 $gd_formats_read_gif = ",gif";
50 ImageDestroy($srcImage);
51 }
52 }
53 }
54
55 if (imagetypes() & IMG_JPG) {
56 $gd_formats[] = "jpg";
57 }
58 if (imagetypes() & IMG_PNG) {
59 $gd_formats[] = "png";
60 }
61 } else {
62 # ancienne methode de detection des formats, qui en plus
63 # est bugguee car elle teste les formats en lecture
64 # alors que la valeur deduite sert a identifier
65 # les formats disponibles en ecriture... (cf. inc_logos)
66
67 if (function_exists('ImageCreateFromJPEG')) {
68 $srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . "test.jpg");
69 if ($srcImage) {
70 $gd_formats[] = "jpg";
71 ImageDestroy($srcImage);
72 }
73 }
74 if (function_exists('ImageCreateFromGIF')) {
75 $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . "test.gif");
76 if ($srcImage) {
77 $gd_formats[] = "gif";
78 ImageDestroy($srcImage);
79 }
80 }
81 if (function_exists('ImageCreateFromPNG')) {
82 $srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . "test.png");
83 if ($srcImage) {
84 $gd_formats[] = "png";
85 ImageDestroy($srcImage);
86 }
87 }
88 }
89
90 if (! empty($gd_formats)) {
91 $gd_formats = join(",", $gd_formats);
92 }
93 ecrire_meta("gd_formats_read", $gd_formats . $gd_formats_read_gif);
94 ecrire_meta("gd_formats", $gd_formats);
95 } // verifier les formats netpbm
96 else {
97 if ($arg == "netpbm") {
98 if (!defined('_PNMSCALE_COMMAND')) {
99 define('_PNMSCALE_COMMAND', 'pnmscale');
100 } // Securite : mes_options.php peut preciser le chemin absolu
101 if (_PNMSCALE_COMMAND == '') {
102 return;
103 }
104 $netpbm_formats = array();
105
106 $jpegtopnm_command = str_replace("pnmscale",
107 "jpegtopnm", _PNMSCALE_COMMAND);
108 $pnmtojpeg_command = str_replace("pnmscale",
109 "pnmtojpeg", _PNMSCALE_COMMAND);
110
111 $vignette = _ROOT_IMG_PACK . "test.jpg";
112 $dest = _DIR_VAR . "test-jpg.jpg";
113 $commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
114 spip_log($commande);
115 exec($commande);
116 if ($taille = @getimagesize($dest)) {
117 if ($taille[1] == 10) {
118 $netpbm_formats[] = "jpg";
119 }
120 }
121 $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
122 $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
123 $vignette = _ROOT_IMG_PACK . "test.gif";
124 $dest = _DIR_VAR . "test-gif.jpg";
125 $commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
126 spip_log($commande);
127 exec($commande);
128 if ($taille = @getimagesize($dest)) {
129 if ($taille[1] == 10) {
130 $netpbm_formats[] = "gif";
131 }
132 }
133
134 $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
135 $vignette = _ROOT_IMG_PACK . "test.png";
136 $dest = _DIR_VAR . "test-gif.jpg";
137 $commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
138 spip_log($commande);
139 exec($commande);
140 if ($taille = @getimagesize($dest)) {
141 if ($taille[1] == 10) {
142 $netpbm_formats[] = "png";
143 }
144 }
145
146
147 if ($netpbm_formats) {
148 $netpbm_formats = join(",", $netpbm_formats);
149 } else {
150 $netpbm_formats = '';
151 }
152 ecrire_meta("netpbm_formats", $netpbm_formats);
153 }
154 }
155
156 // et maintenant envoyer la vignette de tests
157 if (in_array($arg, array("gd1", "gd2", "imagick", "convert", "netpbm"))) {
158 include_spip('inc/filtres');
159 include_spip('inc/filtres_images_mini');
160 $taille_preview = 150;
161 $image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
162
163 $image['fichier_dest'] = _DIR_VAR . "test_$arg";
164
165 if ($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)
166 and ($preview['width'] * $preview['height'] > 0)
167 ) {
168 redirige_par_entete($preview['fichier']);
169 }
170 }
171
172 # image echec
173 redirige_par_entete(chemin_image('puce-rouge-anim.gif'));
174 }