2010-11-17 10 views
66

Mon hébergement Web a déclaré que ImageMagic a été pré-installé sur le serveur. J'ai fait une recherche rapide pour "ImageMagick" dans la sortie de phpinfo() et je n'ai rien trouvé. Je ne peux pas SSH dans le serveur donc est-il un moyen en PHP, je peux vérifier l'installation?Vérifiez l'installation de ImageMagick

Répondre

42

Essayez ceci:

<?php 
//This function prints a text array as an html list. 
function alist ($array) { 
    $alist = "<ul>"; 
    for ($i = 0; $i < sizeof($array); $i++) { 
    $alist .= "<li>$array[$i]"; 
    } 
    $alist .= "</ul>"; 
    return $alist; 
} 
//Try to get ImageMagick "convert" program version number. 
exec("convert -version", $out, $rcode); 
//Print the return code: 0 if OK, nonzero if error. 
echo "Version return code is $rcode <br>"; 
//Print the output of "convert -version"  
echo alist($out); 
?> 
+14

ces essais si l'application ImageMagick est installé, pas Module PHP – stillstanding

+0

Le code retour de la version est 0 * Version: ImageMagick 6.3.7 08/09/09 Q16 http://www.imagemagick.org * Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC –

+0

C'est ce que la page retourne. semble avoir du mal à retourner la version, mais renvoie en quelque sorte les informations de copyright. –

15

Vous pouvez facilement vérifier la classe Imagick en PHP.

if(class_exists("Imagick")) 
{ 
    //Imagick is installed 
} 
+7

** important: ** Parfois, cela retourne FALSE mais 'extension_loaded ('imagick')' retourne TRUE!, donc je suppose que mieux est: 'if (extension_loaded ('imagick') || class_exists (" Imagick ")) {/ * faire Imagick * /}' –

112
if (!extension_loaded('imagick')) 
    echo 'imagick not installed'; 
7

Essayez cette solution one-shot qui devrait comprendre où ImageMagick est, si vous y avez accès ...

Ce trouvé toutes les versions sur mon hébergement GoDaddy.

Téléchargez ce fichier sur votre serveur et appelez le ImageMagick.php ou quelque chose puis exécutez-le. Vous obtiendrez toutes les informations dont vous avez besoin ... j'espère ...

Bonne chance.

<? 
/* 
// This file will run a test on your server to determine the location and versions of ImageMagick. 
//It will look in the most commonly found locations. The last two are where most popular hosts (including "Godaddy") install ImageMagick. 
// 
// Upload this script to your server and run it for a breakdown of where ImageMagick is. 
// 
*/ 
echo '<h2>Test for versions and locations of ImageMagick</h2>'; 
echo '<b>Path: </b> convert<br>'; 

function alist ($array) { //This function prints a text array as an html list. 
    $alist = "<ul>"; 
    for ($i = 0; $i < sizeof($array); $i++) { 
     $alist .= "<li>$array[$i]"; 
    } 
    $alist .= "</ul>"; 
    return $alist; 
} 

exec("convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. 
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. 
echo alist($out); //Print the output of "convert -version" 
echo '<br>'; 
echo '<b>This should test for ImageMagick version 5.x</b><br>'; 
echo '<b>Path: </b> /usr/bin/convert<br>'; 

exec("/usr/bin/convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. 
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. 
echo alist($out); //Print the output of "convert -version" 

echo '<br>'; 
echo '<b>This should test for ImageMagick version 6.x</b><br>'; 
echo '<b>Path: </b> /usr/local/bin/convert<br>'; 

exec("/usr/local/bin/convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. 
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. 
echo alist($out); //Print the output of "convert -version"; 

?> 
+1

convertir un pdf: Beaucoup de thx. joli script. a bien fonctionné sur Hostgator et Godaddy ... pas aussi cool que le cloud ou AWS, mais dans le budget de mes clients de petites entreprises. – zipzit

+1

Après des heures ... ici Google mange ceci: MediaWiki Erreur lors de la création de la vignette: sh:/usr/local/bin/convert: Aucun fichier ou répertoire – Martin

+0

Mine est une application basée sur .NET et Sitecore. Comment vérifier si mon application utilise ImageMagick ou non? –

30

EDIT: Les informations et script ci-dessous applique uniquement à la classe imagick - qui n'est pas ajoutée par défaut avec ImageMagick !!!

Si je veux savoir si ImageMagick est installé et fonctionne en fait comme une extension de php, je coller cet extrait dans un fichier Web accessible

<?php 

error_reporting(E_ALL); 
ini_set('display_errors','1'); 

/* Create a new imagick object */ 
$im = new Imagick(); 

/* Create new image. This will be used as fill pattern */ 
$im->newPseudoImage(50, 50, "gradient:red-black"); 

/* Create imagickdraw object */ 
$draw = new ImagickDraw(); 

/* Start a new pattern called "gradient" */ 
$draw->pushPattern('gradient', 0, 0, 50, 50); 

/* Composite the gradient on the pattern */ 
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im); 

/* Close the pattern */ 
$draw->popPattern(); 

/* Use the pattern called "gradient" as the fill */ 
$draw->setFillPatternURL('#gradient'); 

/* Set font size to 52 */ 
$draw->setFontSize(52); 

/* Annotate some text */ 
$draw->annotation(20, 50, "Hello World!"); 

/* Create a new canvas object and a white image */ 
$canvas = new Imagick(); 
$canvas->newImage(350, 70, "white"); 

/* Draw the ImagickDraw on to the canvas */ 
$canvas->drawImage($draw); 

/* 1px black border around the image */ 
$canvas->borderImage('black', 1, 1); 

/* Set the format to PNG */ 
$canvas->setImageFormat('png'); 

/* Output the image */ 
header("Content-Type: image/png"); 
echo $canvas; 
?> 

Vous devriez voir un graphique Bonjour tout le monde:

enter image description here

5

En bash:

$ convert -version 

ou

$ /usr/local/bin/convert -version 

Pas besoin d'écrire un fichier PHP pour vérifier.

0

Si votre fournisseur d'accès Internet/service d'hébergement a installé ImageMagick et de mettre son emplacement dans la variable d'environnement PATH, vous pouvez trouver ce que les versions sont installées et où l'utilisation:

<?php 
echo "<pre>"; 
system("type -a convert"); 
echo "</pre>"; 
?>