我的网站主机说ImageMagic已经预装在服务器上了。我在phpinfo()的输出中快速搜索"ImageMagick“,什么也没有找到。我无法在服务器中使用SSH,所以在PHP中有没有一种方法可以验证安装?
发布于 2010-11-18 03:25:54
试试这个:
<?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);
?>
发布于 2010-11-18 03:34:45
这是它能得到的最简短和甜蜜的结果:
if (!extension_loaded('imagick'))
echo 'imagick not installed';
发布于 2014-03-16 23:35:44
编辑:以下信息和脚本仅适用于iMagick类-默认情况下不会随ImageMagick一起添加!
如果我想知道imagemagick是否已安装并作为php扩展实际工作,我会将此代码片段粘贴到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;
?>
您应该会看到hello world图形:
https://stackoverflow.com/questions/4208253
复制相似问题