3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
14 * Gestion de l'action testant une librairie graphique
16 * @package SPIP\Core\Configurer
19 if (!defined('_ECRIRE_INC_VERSION')) {
24 * Tester les capacités du serveur à utiliser une librairie graphique
26 * L'argument transmis dans la clé `arg` est le type de librairie parmi
27 * gd2, gd1, netpbm, imagick ou convert
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).
32 function action_tester_dist() {
33 $arg = _request('arg');
35 $gd_formats = array();
36 $gd_formats_read_gif = "";
37 // verifier les formats acceptes par GD
39 // Si GD est installe et php >= 4.0.2
40 if (function_exists('imagetypes')) {
42 if (imagetypes() & IMG_GIF
) {
43 $gd_formats[] = "gif";
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");
49 $gd_formats_read_gif = ",gif";
50 ImageDestroy($srcImage);
55 if (imagetypes() & IMG_JPG
) {
56 $gd_formats[] = "jpg";
58 if (imagetypes() & IMG_PNG
) {
59 $gd_formats[] = "png";
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)
67 if (function_exists('ImageCreateFromJPEG')) {
68 $srcImage = @ImageCreateFromJPEG
(_ROOT_IMG_PACK
. "test.jpg");
70 $gd_formats[] = "jpg";
71 ImageDestroy($srcImage);
74 if (function_exists('ImageCreateFromGIF')) {
75 $srcImage = @ImageCreateFromGIF
(_ROOT_IMG_PACK
. "test.gif");
77 $gd_formats[] = "gif";
78 ImageDestroy($srcImage);
81 if (function_exists('ImageCreateFromPNG')) {
82 $srcImage = @ImageCreateFromPNG
(_ROOT_IMG_PACK
. "test.png");
84 $gd_formats[] = "png";
85 ImageDestroy($srcImage);
90 if (! empty($gd_formats)) {
91 $gd_formats = join(",", $gd_formats);
93 ecrire_meta("gd_formats_read", $gd_formats . $gd_formats_read_gif);
94 ecrire_meta("gd_formats", $gd_formats);
95 } // verifier les formats netpbm
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
== '') {
104 $netpbm_formats = array();
106 $jpegtopnm_command = str_replace("pnmscale",
107 "jpegtopnm", _PNMSCALE_COMMAND
);
108 $pnmtojpeg_command = str_replace("pnmscale",
109 "pnmtojpeg", _PNMSCALE_COMMAND
);
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";
116 if ($taille = @getimagesize
($dest)) {
117 if ($taille[1] == 10) {
118 $netpbm_formats[] = "jpg";
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";
128 if ($taille = @getimagesize
($dest)) {
129 if ($taille[1] == 10) {
130 $netpbm_formats[] = "gif";
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";
140 if ($taille = @getimagesize
($dest)) {
141 if ($taille[1] == 10) {
142 $netpbm_formats[] = "png";
147 if ($netpbm_formats) {
148 $netpbm_formats = join(",", $netpbm_formats);
150 $netpbm_formats = '';
152 ecrire_meta("netpbm_formats", $netpbm_formats);
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');
163 $image['fichier_dest'] = _DIR_VAR
. "test_$arg";
165 if ($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)
166 and ($preview['width'] * $preview['height'] > 0)
168 redirige_par_entete($preview['fichier']);
173 redirige_par_entete(chemin_image('puce-rouge-anim.gif'));