2010-11-17 73 views
66

我的虚拟主机表示ImageMagic已经预先安装在服务器上。我在phpinfo()的输出中快速搜索了“ImageMagick”,但我什么也没找到。我不能在服务器中SSH,所以有没有办法在PHP我可以验证安装?验证ImageMagick安装

回答

42

试试这个:

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

此测试是否安装了ImageMagick的应用程序,而不是PHP模块 – stillstanding 2010-11-17 19:46:39

+0

版本返回码是0 *版本:ImageMagick 6.3.7 08/09/09 Q16 http://www.imagemagick.org *版权:Copyright(C)1999-2008 ImageMagick Studio LLC – 2010-11-17 19:50:34

+0

这是什么该页面返回。似乎它返回版本有问题,但不知何故返回版权信息。 – 2010-11-17 19:51:36

15

您可以轻松地为您在PHP的Imagick类。

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

**重要:**有时这会返回FALSE,但是'extension_loaded('imagick')'返回TRUE!,所以我想更好的是:'if(extension_loaded('imagick')|| class_exists(“Imagick”)){/ *做Imagick * /}' – 2014-04-17 07:43:21

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

试试这个一次性的解决方案,应该找出其中ImageMagick的是,如果你有机会获得它...

这才发现我的Godaddy主机的所有版本。

将此文件上传到您的服务器并将其命名ImageMagick.php或其他内容,然后运行它。你会得到你需要的所有信息...希望...

祝你好运。

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

转换pdf:许多thx。很好的脚本。在hostgator和godaddy上运行良好......没有云或AWS那么酷,但在我的小企业客户的预算之内。 – zipzit 2013-10-08 21:41:37

+1

工作时间...谷歌吃这个:MediaWiki创建缩略图时出错:sh:/ usr/local/bin/convert:没有这样的文件或目录 – Martin 2014-01-25 14:55:13

+0

Mine是基于.NET和Sitecore的应用程序。如何检查我的应用程序是否使用ImageMagick? – 2016-05-16 06:26:11

30

编辑:下面的信息和脚本只适用于iMagick类 - 这是不是默认添加与ImageMagick的!

如果我想知道是否安装ImageMagick的和实际工作作为PHP扩展,我贴这个片段到网络访问的文件

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

你应该可以看到一个Hello World图形:

​​

5

在bash:

$ convert -version 

$ /usr/local/bin/convert -version 

不需要编写任何PHP文件只是为了检查。

0

如果你的ISP /托管服务已经安装了ImageMagick的,并把它的位置在PATH环境变量中,你可以找到所安装的版本,并在那里使用:

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