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