我的网站主机说ImageMagic已经预装在服务器上了。我在phpinfo()的输出中快速搜索了"ImageMagick",但没有找到任何信息。由于我无法通过SSH登录该服务器,因此是否有在PHP中验证安装的方法?
我的网站主机说ImageMagic已经预装在服务器上了。我在phpinfo()的输出中快速搜索了"ImageMagick",但没有找到任何信息。由于我无法通过SSH登录该服务器,因此是否有在PHP中验证安装的方法?
if (!extension_loaded('imagick')){
echo 'imagick not installed';
}
试一下这个:
<?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);
?>
编辑:以下信息和脚本仅适用于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”图形:
$ convert -version
或者$ /usr/local/bin/convert -version
无需编写任何 PHP 文件来进行检查。
你可以在PHP中轻松地检查Imagick类。
if( class_exists("Imagick") )
{
//Imagick is installed
}
extension_loaded('imagick')
返回TRUE!因此,我认为更好的方法是:if( extension_loaded('imagick') || class_exists("Imagick") ){ /*使用Imagick*/ }
- jave.webclass_exists(Imagick::class)
的情况。那可能更可靠一些。 - hostingutilities.com在Bash中,您可以检查Imagick是否为已安装的模块:
$ php -m | grep imagick
如果响应为空,则表示未安装。这在我的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";
?>
仅测试IMagick PHP扩展(而不是完整的ImageMagick套件),请将以下内容保存为PHP文件(testImagick.php),然后在控制台中运行:php testImagick.php
<?php
$image = new Imagick();
$image->newImage(1, 1, new ImagickPixel('#ffffff'));
$image->setImageFormat('png');
$pngData = $image->getImagesBlob();
echo strpos($pngData, "\x89PNG\r\n\x1a\n") === 0 ? 'Ok' : 'Failed';
echo "\n";
信用: https://mlocati.github.io/articles/php-windows-imagick.html
如果您在 Windows 上使用 PHP 并且需要使用 Imagick 扩展来处理图像,则可能会遇到一些问题。这篇文章将解释如何在 Windows 上安装和配置 Imagick 以及如何解决常见错误。<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>
php -r 'echo "imagick is ".(extension_loaded("imagick")?"":"not ")."installed\n";'
- Jon Gibbins