Completed
Push — master ( edc33a...f1c896 )
by cam
04:43
created
ecrire/action/tester.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -30,154 +30,154 @@  discard block
 block discarded – undo
30 30
  * redirige sur l'image ainsi créée (sinon sur une image d'echec).
31 31
  **/
32 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
-			if (imagetypes() & IMG_GIF) {
42
-				$gd_formats[] = "gif";
43
-			} else {
44
-				# Attention GD sait lire le gif mais pas forcement l'ecrire
45
-				if (function_exists('ImageCreateFromGIF')) {
46
-					$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . "test.gif");
47
-					if ($srcImage) {
48
-						$gd_formats_read_gif = ",gif";
49
-						ImageDestroy($srcImage);
50
-					}
51
-				}
52
-			}
53
-
54
-			if (imagetypes() & IMG_JPG) {
55
-				$gd_formats[] = "jpg";
56
-			}
57
-			if (imagetypes() & IMG_PNG) {
58
-				$gd_formats[] = "png";
59
-			}
60
-			if (imagetypes() & IMG_WEBP) {
61
-				$gd_formats[] = "webp";
62
-			}
63
-		} else {
64
-			# ancienne methode de detection des formats, qui en plus
65
-			# est bugguee car elle teste les formats en lecture
66
-			# alors que la valeur deduite sert a identifier
67
-			# les formats disponibles en ecriture... (cf. inc_logos)
68
-
69
-			if (function_exists('ImageCreateFromJPEG')) {
70
-				$srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . "test.jpg");
71
-				if ($srcImage) {
72
-					$gd_formats[] = "jpg";
73
-					ImageDestroy($srcImage);
74
-				}
75
-			}
76
-			if (function_exists('ImageCreateFromGIF')) {
77
-				$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . "test.gif");
78
-				if ($srcImage) {
79
-					$gd_formats[] = "gif";
80
-					ImageDestroy($srcImage);
81
-				}
82
-			}
83
-			if (function_exists('ImageCreateFromPNG')) {
84
-				$srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . "test.png");
85
-				if ($srcImage) {
86
-					$gd_formats[] = "png";
87
-					ImageDestroy($srcImage);
88
-				}
89
-			}
90
-			if (function_exists('ImageCreateFromWEBP')) {
91
-				$srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . "test.webp");
92
-				if ($srcImage) {
93
-					$gd_formats[] = "webp";
94
-					ImageDestroy($srcImage);
95
-				}
96
-			}
97
-		}
98
-
99
-		if (! empty($gd_formats)) {
100
-			$gd_formats = join(",", $gd_formats);
101
-		}
102
-		ecrire_meta("gd_formats_read", $gd_formats . $gd_formats_read_gif);
103
-		ecrire_meta("gd_formats", $gd_formats);
104
-	} // verifier les formats netpbm
105
-	else {
106
-		if ($arg == "netpbm") {
107
-			if (!defined('_PNMSCALE_COMMAND')) {
108
-				define('_PNMSCALE_COMMAND', 'pnmscale');
109
-			} // Securite : mes_options.php peut preciser le chemin absolu
110
-			if (_PNMSCALE_COMMAND == '') {
111
-				return;
112
-			}
113
-			$netpbm_formats = array();
114
-
115
-			$jpegtopnm_command = str_replace("pnmscale",
116
-				"jpegtopnm", _PNMSCALE_COMMAND);
117
-			$pnmtojpeg_command = str_replace("pnmscale",
118
-				"pnmtojpeg", _PNMSCALE_COMMAND);
119
-
120
-			$vignette = _ROOT_IMG_PACK . "test.jpg";
121
-			$dest = _DIR_VAR . "test-jpg.jpg";
122
-			$commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
123
-			spip_log($commande);
124
-			exec($commande);
125
-			if ($taille = @getimagesize($dest)) {
126
-				if ($taille[1] == 10) {
127
-					$netpbm_formats[] = "jpg";
128
-				}
129
-			}
130
-			$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
131
-			$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
132
-			$vignette = _ROOT_IMG_PACK . "test.gif";
133
-			$dest = _DIR_VAR . "test-gif.jpg";
134
-			$commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
135
-			spip_log($commande);
136
-			exec($commande);
137
-			if ($taille = @getimagesize($dest)) {
138
-				if ($taille[1] == 10) {
139
-					$netpbm_formats[] = "gif";
140
-				}
141
-			}
142
-
143
-			$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
144
-			$vignette = _ROOT_IMG_PACK . "test.png";
145
-			$dest = _DIR_VAR . "test-gif.jpg";
146
-			$commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
147
-			spip_log($commande);
148
-			exec($commande);
149
-			if ($taille = @getimagesize($dest)) {
150
-				if ($taille[1] == 10) {
151
-					$netpbm_formats[] = "png";
152
-				}
153
-			}
154
-
155
-
156
-			if ($netpbm_formats) {
157
-				$netpbm_formats = join(",", $netpbm_formats);
158
-			} else {
159
-				$netpbm_formats = '';
160
-			}
161
-			ecrire_meta("netpbm_formats", $netpbm_formats);
162
-		}
163
-	}
164
-
165
-	// et maintenant envoyer la vignette de tests
166
-	if (in_array($arg, array("gd1", "gd2", "imagick", "convert", "netpbm"))) {
167
-		include_spip('inc/filtres');
168
-		include_spip('inc/filtres_images_mini');
169
-		$taille_preview = 150;
170
-		$image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
171
-
172
-		$image['fichier_dest'] = _DIR_VAR . "test_$arg";
173
-
174
-		if ($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)
175
-			and ($preview['width'] * $preview['height'] > 0)
176
-		) {
177
-			redirige_par_entete($preview['fichier']);
178
-		}
179
-	}
180
-
181
-	# image echec
182
-	redirige_par_entete(chemin_image('echec-reducteur-xx.svg'));
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
+            if (imagetypes() & IMG_GIF) {
42
+                $gd_formats[] = "gif";
43
+            } else {
44
+                # Attention GD sait lire le gif mais pas forcement l'ecrire
45
+                if (function_exists('ImageCreateFromGIF')) {
46
+                    $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . "test.gif");
47
+                    if ($srcImage) {
48
+                        $gd_formats_read_gif = ",gif";
49
+                        ImageDestroy($srcImage);
50
+                    }
51
+                }
52
+            }
53
+
54
+            if (imagetypes() & IMG_JPG) {
55
+                $gd_formats[] = "jpg";
56
+            }
57
+            if (imagetypes() & IMG_PNG) {
58
+                $gd_formats[] = "png";
59
+            }
60
+            if (imagetypes() & IMG_WEBP) {
61
+                $gd_formats[] = "webp";
62
+            }
63
+        } else {
64
+            # ancienne methode de detection des formats, qui en plus
65
+            # est bugguee car elle teste les formats en lecture
66
+            # alors que la valeur deduite sert a identifier
67
+            # les formats disponibles en ecriture... (cf. inc_logos)
68
+
69
+            if (function_exists('ImageCreateFromJPEG')) {
70
+                $srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . "test.jpg");
71
+                if ($srcImage) {
72
+                    $gd_formats[] = "jpg";
73
+                    ImageDestroy($srcImage);
74
+                }
75
+            }
76
+            if (function_exists('ImageCreateFromGIF')) {
77
+                $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . "test.gif");
78
+                if ($srcImage) {
79
+                    $gd_formats[] = "gif";
80
+                    ImageDestroy($srcImage);
81
+                }
82
+            }
83
+            if (function_exists('ImageCreateFromPNG')) {
84
+                $srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . "test.png");
85
+                if ($srcImage) {
86
+                    $gd_formats[] = "png";
87
+                    ImageDestroy($srcImage);
88
+                }
89
+            }
90
+            if (function_exists('ImageCreateFromWEBP')) {
91
+                $srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . "test.webp");
92
+                if ($srcImage) {
93
+                    $gd_formats[] = "webp";
94
+                    ImageDestroy($srcImage);
95
+                }
96
+            }
97
+        }
98
+
99
+        if (! empty($gd_formats)) {
100
+            $gd_formats = join(",", $gd_formats);
101
+        }
102
+        ecrire_meta("gd_formats_read", $gd_formats . $gd_formats_read_gif);
103
+        ecrire_meta("gd_formats", $gd_formats);
104
+    } // verifier les formats netpbm
105
+    else {
106
+        if ($arg == "netpbm") {
107
+            if (!defined('_PNMSCALE_COMMAND')) {
108
+                define('_PNMSCALE_COMMAND', 'pnmscale');
109
+            } // Securite : mes_options.php peut preciser le chemin absolu
110
+            if (_PNMSCALE_COMMAND == '') {
111
+                return;
112
+            }
113
+            $netpbm_formats = array();
114
+
115
+            $jpegtopnm_command = str_replace("pnmscale",
116
+                "jpegtopnm", _PNMSCALE_COMMAND);
117
+            $pnmtojpeg_command = str_replace("pnmscale",
118
+                "pnmtojpeg", _PNMSCALE_COMMAND);
119
+
120
+            $vignette = _ROOT_IMG_PACK . "test.jpg";
121
+            $dest = _DIR_VAR . "test-jpg.jpg";
122
+            $commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
123
+            spip_log($commande);
124
+            exec($commande);
125
+            if ($taille = @getimagesize($dest)) {
126
+                if ($taille[1] == 10) {
127
+                    $netpbm_formats[] = "jpg";
128
+                }
129
+            }
130
+            $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
131
+            $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
132
+            $vignette = _ROOT_IMG_PACK . "test.gif";
133
+            $dest = _DIR_VAR . "test-gif.jpg";
134
+            $commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
135
+            spip_log($commande);
136
+            exec($commande);
137
+            if ($taille = @getimagesize($dest)) {
138
+                if ($taille[1] == 10) {
139
+                    $netpbm_formats[] = "gif";
140
+                }
141
+            }
142
+
143
+            $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
144
+            $vignette = _ROOT_IMG_PACK . "test.png";
145
+            $dest = _DIR_VAR . "test-gif.jpg";
146
+            $commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
147
+            spip_log($commande);
148
+            exec($commande);
149
+            if ($taille = @getimagesize($dest)) {
150
+                if ($taille[1] == 10) {
151
+                    $netpbm_formats[] = "png";
152
+                }
153
+            }
154
+
155
+
156
+            if ($netpbm_formats) {
157
+                $netpbm_formats = join(",", $netpbm_formats);
158
+            } else {
159
+                $netpbm_formats = '';
160
+            }
161
+            ecrire_meta("netpbm_formats", $netpbm_formats);
162
+        }
163
+    }
164
+
165
+    // et maintenant envoyer la vignette de tests
166
+    if (in_array($arg, array("gd1", "gd2", "imagick", "convert", "netpbm"))) {
167
+        include_spip('inc/filtres');
168
+        include_spip('inc/filtres_images_mini');
169
+        $taille_preview = 150;
170
+        $image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
171
+
172
+        $image['fichier_dest'] = _DIR_VAR . "test_$arg";
173
+
174
+        if ($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)
175
+            and ($preview['width'] * $preview['height'] > 0)
176
+        ) {
177
+            redirige_par_entete($preview['fichier']);
178
+        }
179
+    }
180
+
181
+    # image echec
182
+    redirige_par_entete(chemin_image('echec-reducteur-xx.svg'));
183 183
 }
Please login to merge, or discard this patch.