8873f3a0956e76e9816fa842dd93555b98b85d8d
[velocampus/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-2011 *
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 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 // Tester nos capacites
16 // http://doc.spip.org/@action_tester_dist
17 function action_tester_dist() {
18 $arg = _request('arg');
19
20 // verifier les formats acceptes par GD
21 if ($arg == "gd1") {
22 // Si GD est installe et php >= 4.0.2
23 if (function_exists('imagetypes')) {
24
25 if (imagetypes() & IMG_GIF) {
26 $gd_formats[] = "gif";
27 } else {
28 # Attention GD sait lire le gif mais pas forcement l'ecrire
29 if (function_exists('ImageCreateFromGIF')) {
30 $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK."test.gif");
31 if ($srcImage) {
32 $gd_formats_read_gif = ",gif";
33 ImageDestroy( $srcImage );
34 }
35 }
36 }
37
38 if (imagetypes() & IMG_JPG)
39 $gd_formats[] = "jpg";
40 if (imagetypes() & IMG_PNG)
41 $gd_formats[] = "png";
42 }
43
44 else { # ancienne methode de detection des formats, qui en plus
45 # est bugguee car elle teste les formats en lecture
46 # alors que la valeur deduite sert a identifier
47 # les formats disponibles en ecriture... (cf. inc_logos)
48
49 $gd_formats = Array();
50 if (function_exists('ImageCreateFromJPEG')) {
51 $srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK."test.jpg");
52 if ($srcImage) {
53 $gd_formats[] = "jpg";
54 ImageDestroy( $srcImage );
55 }
56 }
57 if (function_exists('ImageCreateFromGIF')) {
58 $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK."test.gif");
59 if ($srcImage) {
60 $gd_formats[] = "gif";
61 ImageDestroy( $srcImage );
62 }
63 }
64 if (function_exists('ImageCreateFromPNG')) {
65 $srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK."test.png");
66 if ($srcImage) {
67 $gd_formats[] = "png";
68 ImageDestroy( $srcImage );
69 }
70 }
71 }
72
73 if ($gd_formats) $gd_formats = join(",", $gd_formats);
74 ecrire_meta("gd_formats_read", $gd_formats.$gd_formats_read_gif);
75 ecrire_meta("gd_formats", $gd_formats);
76 }
77
78 // verifier les formats netpbm
79 else if ($arg == "netpbm") {
80 define('_PNMSCALE_COMMAND', 'pnmscale'); // chemin a changer dans mes_options
81 if (_PNMSCALE_COMMAND == '') return;
82 $netpbm_formats= Array();
83
84 $jpegtopnm_command = str_replace("pnmscale",
85 "jpegtopnm", _PNMSCALE_COMMAND);
86 $pnmtojpeg_command = str_replace("pnmscale",
87 "pnmtojpeg", _PNMSCALE_COMMAND);
88
89 $vignette = _ROOT_IMG_PACK."test.jpg";
90 $dest = _DIR_VAR . "test-jpg.jpg";
91 $commande = "$jpegtopnm_command $vignette | "._PNMSCALE_COMMAND." -width 10 | $pnmtojpeg_command > $dest";
92 spip_log($commande);
93 exec($commande);
94 if ($taille = @getimagesize($dest)) {
95 if ($taille[1] == 10) $netpbm_formats[] = "jpg";
96 }
97 $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
98 $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
99 $vignette = _ROOT_IMG_PACK."test.gif";
100 $dest = _DIR_VAR . "test-gif.jpg";
101 $commande = "$giftopnm_command $vignette | "._PNMSCALE_COMMAND." -width 10 | $pnmtojpeg_command > $dest";
102 spip_log($commande);
103 exec($commande);
104 if ($taille = @getimagesize($dest)) {
105 if ($taille[1] == 10) $netpbm_formats[] = "gif";
106 }
107
108 $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
109 $vignette = _ROOT_IMG_PACK."test.png";
110 $dest = _DIR_VAR . "test-gif.jpg";
111 $commande = "$pngtopnm_command $vignette | "._PNMSCALE_COMMAND." -width 10 | $pnmtojpeg_command > $dest";
112 spip_log($commande);
113 exec($commande);
114 if ($taille = @getimagesize($dest)) {
115 if ($taille[1] == 10) $netpbm_formats[] = "png";
116 }
117
118
119 if ($netpbm_formats)
120 $netpbm_formats = join(",", $netpbm_formats);
121 else
122 $netpbm_formats = '';
123 ecrire_meta("netpbm_formats", $netpbm_formats);
124 }
125
126 // et maintenant envoyer la vignette de tests
127 if (in_array($arg,array("gd1","gd2","imagick","convert","netpbm"))) {
128 include_spip('inc/filtres');
129 include_spip('inc/filtres_images_mini');
130 $taille_preview = 150;
131 $image = _image_valeurs_trans(_DIR_IMG_PACK.'test_image.jpg',"reduire-$taille_preview-$taille_preview",'jpg');
132
133 $image['fichier_dest']=_DIR_VAR."test_$arg";
134 if ($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)
135 AND ($preview['width'] * $preview['height'] > 0))
136 redirige_par_entete($preview['fichier']);
137 }
138
139 # image echec
140 redirige_par_entete(chemin_image('puce-rouge-anim.gif'));
141 }
142 ?>