From 312705a8cd9b4132d85161bae4976b21610381f4 Mon Sep 17 00:00:00 2001 From: ARNO* <arno@rezo.net> Date: Fri, 8 Oct 2004 15:20:00 +0000 Subject: [PATCH] Correction spip_image_reduite et affin'e choix netpbm --- ecrire/config-fonctions.php3 | 3 ++- ecrire/inc_logos.php3 | 21 +++++++++++++++++--- inc-public.php3 | 2 -- spip_image.php3 | 38 +++++++++++++++++++++++++++++++++++- spip_image_reduite.php3 | 13 ++++++------ 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/ecrire/config-fonctions.php3 b/ecrire/config-fonctions.php3 index 614586faee..4d5a4dc2d7 100644 --- a/ecrire/config-fonctions.php3 +++ b/ecrire/config-fonctions.php3 @@ -79,6 +79,7 @@ else { if ($image_process) { ecrire_meta('image_process', $image_process); ecrire_metas(); // Puisque le switch se fait par lire_meta. + // mettre a jour les formats graphiques lisibles switch (lire_meta('image_process')) { case 'gd1': @@ -88,7 +89,7 @@ else { $formats_graphiques = lire_meta('gd_formats'); break; case 'netpbm': - $formats_graphiques = 'jpg'; + $formats_graphiques = lire_meta('gd_formats'); break; case 'convert': $formats_graphiques = 'gif,jpg,png'; diff --git a/ecrire/inc_logos.php3 b/ecrire/inc_logos.php3 index f596269be1..ef1f3e8947 100644 --- a/ecrire/inc_logos.php3 +++ b/ecrire/inc_logos.php3 @@ -197,7 +197,7 @@ function creer_vignette($image, $maxWidth, $maxHeight, $format, $destdir, $destf $formats_sortie = array('png','jpg','gif'); else $formats_sortie = array('jpg','png','gif'); - + if ($process == 'AUTO') $process = lire_meta('image_process'); @@ -258,11 +258,26 @@ function creer_vignette($image, $maxWidth, $maxHeight, $format, $destdir, $destf } } if ($process == "netpbm") { + $format_sortie = "jpg"; + $vignette = $destination.".".$format_sortie; if ($format == "jpg") { - $vignette = $destination.".".$format; exec("$djpeg_command $image | $pnmscale_command -width $destWidth | $cjpeg_command -outfile $vignette"); if (!@file_exists($vignette)) { - spip_log("echec netpbm sur $vignette"); + spip_log("echec netpbm-jpg sur $vignette"); + return; + } + } else if ($format == "gif") { + $giftopnm_command = ereg_replace("pnmscale", "giftopnm", $pnmscale_command); + exec("$giftopnm_command $image | $pnmscale_command -width $destWidth | $cjpeg_command -outfile $vignette"); + if (!@file_exists($vignette)) { + spip_log("echec netpbm-gif sur $vignette"); + return; + } + } else if ($format == "png") { + $pngtopnm_command = ereg_replace("pnmscale", "pngtopnm", $pnmscale_command); + exec("$pngtopnm_command $image | $pnmscale_command -width $destWidth | $cjpeg_command -outfile $vignette"); + if (!@file_exists($vignette)) { + spip_log("echec netpbm-png sur $vignette"); return; } } diff --git a/inc-public.php3 b/inc-public.php3 index 2a21236a2b..5dd6089938 100644 --- a/inc-public.php3 +++ b/inc-public.php3 @@ -12,12 +12,10 @@ if (defined("_INC_PUBLIC")) { if ($page['lang_select']) lang_dselect(); } - // Premier appel inc-public else { define("_INC_PUBLIC", "1"); include ("ecrire/inc_version.php3"); - // // Initialisations // diff --git a/spip_image.php3 b/spip_image.php3 index daf840759e..dd8ba110f6 100644 --- a/spip_image.php3 +++ b/spip_image.php3 @@ -44,7 +44,8 @@ function effacer_image($nom) { } function tester_vignette ($test_vignette) { -// verifier les formats acceptes par GD + global $djpeg_command, $cjpeg_command, $pnmscale_command; + // verifier les formats acceptes par GD if ($test_vignette == "gd1") { $gd_formats = Array(); if (function_exists('ImageCreateFromJPEG')) { @@ -69,6 +70,41 @@ function tester_vignette ($test_vignette) { } } + if ($gd_formats) $gd_formats = join(",", $gd_formats); + ecrire_meta("gd_formats", $gd_formats); + ecrire_metas(); + } + // verifier les formats netpbm + else if ($test_vignette == "netpbm") { + $gd_formats = Array(); + + $vignette = _DIR_IMG . "test.jpg"; + $dest = _DIR_IMG . "test-10.jpg"; + exec("$djpeg_command $vignette | $pnmscale_command -width 10 | $cjpeg_command -outfile $dest"); + if ($taille = @getimagesize($dest)) { + if ($taille[1] == 10) $gd_formats[] = "jpg"; + } + ImageDestroy( $dest ); + + + $giftopnm_command = ereg_replace("pnmscale", "giftopnm", $pnmscale_command); + $vignette = _DIR_IMG . "test.gif"; + $dest = _DIR_IMG . "test-gif.jpg"; + exec("$giftopnm_command $vignette | $pnmscale_command -width 10 | $cjpeg_command -outfile $dest"); + if ($taille = @getimagesize($dest)) { + if ($taille[1] == 10) $gd_formats[] = "gif"; + } + ImageDestroy( $dest ); + $pngtopnm_command = ereg_replace("pnmscale", "pngtopnm", $pnmscale_command); + $vignette = _DIR_IMG . "test.png"; + $dest = _DIR_IMG . "test-gif.jpg"; + exec("$pngtopnm_command $vignette | $pnmscale_command -width 10 | $cjpeg_command -outfile $dest"); + if ($taille = @getimagesize($dest)) { + if ($taille[1] == 10) $gd_formats[] = "png"; + } + ImageDestroy( $dest ); + + if ($gd_formats) $gd_formats = join(",", $gd_formats); ecrire_meta("gd_formats", $gd_formats); ecrire_metas(); diff --git a/spip_image_reduite.php3 b/spip_image_reduite.php3 index 88574e2755..66a2ab362e 100644 --- a/spip_image_reduite.php3 +++ b/spip_image_reduite.php3 @@ -7,12 +7,12 @@ include_ecrire("inc_admin.php3"); if (!$taille_y) $taille_y = $taille_x; - + if (eregi("(.*)\.(jpg|gif|png)$", $logo, $regs)) { if ($i = cherche_image_nommee($regs[1], array($regs[2])) AND verifier_action_auteur("reduire $taille_x $taille_y", $hash, $hash_id_auteur)) { - list($dir,$nom,$format) = $i; + list($dir,$nom,$format) = $i; $logo = $dir . $nom . '.' . $format; include_ecrire("inc_logos.php3"); $suffixe = '-'.$taille_x.'x'.$taille_y; @@ -24,11 +24,10 @@ if (eregi("(.*)\.(jpg|gif|png)$", $logo, $regs)) { //echo "<img src='$vignette' name='$name' border='0' align='$align' alt='' hspace='$espace' vspace='$espace' width='$width' height='$height' class='spip_logos' />"; $retour = $vignette; } - else if ($taille_origine = getimagesize($logo)) - list ($destWidth,$destHeight) = image_ratio($taille_origine[0], $taille_origine[1], $taille_x, $taille_y); - //echo "<img src='$logo' name='$name' width='$destWidth' height='$destHeight' border='0' align='$align' alt='' hspace='$espace' vspace='$espace' class='spip_logos' />"; - $retour = $logo; - + else if ($taille_origine = getimagesize($logo)) { + //list ($destWidth,$destHeight) = image_ratio($taille_origine[0], $taille_origine[1], $taille_x, $taille_y); + $retour = $logo; + } // Afficher l'image resultante, meme grande... // header("Content-type: image/$format"); -- GitLab