2010-11-17 54 views
66

Mi alojamiento web dice que ImageMagic ha sido preinstalado en el servidor. Hice una búsqueda rápida de "ImageMagick" en la salida de phpinfo() y no encontré nada. No puedo SSH en el servidor, ¿hay alguna forma en PHP para verificar la instalación?Verificar la instalación de ImageMagick

Respuesta

42

Prueba esto:

<?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

estas pruebas si se ha instalado la aplicación ImageMagick, no el Módulo PHP – stillstanding

+0

El código de devolución de la versión es 0 * Versión: ImageMagick 6.3.7 08/09/09 Q16 http://www.imagemagick.org * Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC –

+0

Esto es lo que la página regresa Parece que tiene problemas para devolver la versión, pero de alguna manera devuelve la información de copyright. –

15

Puede comprobar fácilmente para la clase Imagick en PHP.

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

** importante: ** A veces, esto devuelve FALSE pero 'extension_loaded ('imagick')' ¡devuelve TRUE!, así que supongo que es mejor: 'if (extensión_cargada ('imagick') || class_exists (" Imagick ")) {/ * do Imagick * /}' –

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

Pruebe esta solución one-shot que debe averiguar dónde ImageMagick es, si tiene acceso a ella ...

Esta conocer todas las versiones en mi alojamiento Godaddy.

Cargue este archivo en su servidor y llámelo ImageMagick.php o algo así y ejecútelo. Obtendrá toda la información que necesita ... con suerte ...

Buena suerte.

<? 
/* 
// 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: Many thx. buena escritura. funcionó bien en hostgator y godaddy ... no tan genial como la nube o AWS, pero dentro del presupuesto de mis clientes de pequeñas empresas. – zipzit

+1

Después de horas ... aquí Google come esto: MediaWiki Error al crear una miniatura: sh:/usr/local/bin/convert: No existe tal archivo o directorio – Martin

+0

Mine es una aplicación basada en .NET y Sitecore. ¿Cómo verifico mi aplicación si está usando ImageMagick o no? –

30

EDIT: La información y el guión a continuación sólo se aplica a la clase imagick - que no se añade de forma predeterminada con ImageMagick !!!

Si yo quiero saber si se ha instalado ImageMagick y en realidad trabaja como una extensión php, me pega este fragmento en un archivo accesible Web

<?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; 
?> 

Debería ver un gráfico hola mundo:

enter image description here

5

En bash:

$ convert -version 

o

$ /usr/local/bin/convert -version 

No hay necesidad de escribir ningún archivo PHP solo para verificarlo.

0

Si su ISP/servicio de alojamiento ha instalado ImageMagick y poner su ubicación en la variable de entorno PATH, puede encontrar qué versiones se instalan y donde usando:

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