验证ImageMagick安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证ImageMagick安装相关的知识,希望对你有一定的参考价值。

我的网站托管说ImageMagic已预先安装在服务器上。我在phpinfo()的输出中快速搜索了“ImageMagick”,但我什么都没发现。我不能在服务器上SSH,所以有没有办法在PHP我可以验证安装?

答案

试试这个:

<?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); 
?>
另一答案

这是短暂而甜蜜的:

if (!extension_loaded('imagick'))
    echo 'imagick not installed';
另一答案

编辑:下面的信息和脚本仅适用于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图形:

另一答案

您可以在PHP中轻松检查Imagick类。

if( class_exists("Imagick") )
{
    //Imagick is installed
}
另一答案

在bash中:

$ convert -version

要么

$ /usr/local/bin/convert -version

无需编写任何PHP文件即可查看。

另一答案

试试这个一次性解决方案应该找出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";

?>
另一答案

如果您的ISP /托管服务已安装ImageMagick并将其位置放在PATH环境变量中,您可以找到安装的版本以及使用位置:

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

在Bash中,您可以检查Imagick是否是已安装的模块:

$ php -m | grep imagick

如果响应为空,则表示未安装。

另一答案

要仅测试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
x1a
") === 0 ? 'Ok' : 'Failed';
echo "
";

信用:https://mlocati.github.io/articles/php-windows-imagick.html

以上是关于验证ImageMagick安装的主要内容,如果未能解决你的问题,请参考以下文章

ImageMagick简单记录

求教imagemagick安装方法

我已经安装了 ImageMagick,但我仍然在图像库中遇到错误

如何在配置中为安装在 Windows 机器上的 ImageMagick 库设置 library_path

php安装imagemagick问题。

安装ImageMagick