0

gmagick 是 imagemagick 的更新版本,具有更多功能,它占用的资源更少且速度更快,但问题是网络上关于这个精彩工具的讨论很少,我最近在 http://devzone.zend.com/1559上遇到了这个/manipulating-images-with-php-and-graphicsmagick/ 但我无法在 Windows 机器上安装它,因为 phpize 没有工作,所以我尝试了一些其他方式以及一些如何设法进入 phpinfo 页面,但我无法让它进一步工作我甚至没有用 gmagick 打开单个图像这是我使用的代码

     <?php
     $path="gallery/img1.jpg";
     // initialize object
     $image = new Gmagick($path);
     echo $image;
    // read image file
   $file = 'gallery/img1.jpg';
   $image->readImage($file);
   echo '<img src="' . $file . '" width="200" height="150" /> <br/>';
   ?>

我使用此代码来实例化 gmagick 类并打开图像,但我遇到非常大的错误,如下所示 致命错误:未捕获的异常 'GmagickException' 并在 C:\xampp\htdocs 中显示消息“无法打开文件(gallery/img1.jpg)” \junk\imgproc\imgproc1.php:4 堆栈跟踪:#0 C:\xampp\htdocs\junk\imgproc\imgproc1.php(4): Gmagick->__construct('gallery/img1.jp...') # 1 {main} 在第 4 行的 C:\xampp\htdocs\junk\imgproc\imgproc1.php 中抛出

4

1 回答 1

3

A)回答标题中的问题(可能会在此处引导其他读者):

可在此处获得适用于 PHP 的 GraphicsMagick 扩展的 Windows 构建:http: //valokuva.org/builds/

phpinfo();通过查看网络服务器的输出来检查您是否需要线程安全版本。寻找条目Thread Safety。在该条目中PHP Extension Build,您还应该找到您需要的 VC 版本,例如API20090626,TS,VC9VC9。

下载符合您条件的最新版本,将其放入您的 PHP/ext 目录并将其添加到您的 php.ini 中,如下所示:

extension=php_gmagick_ts.dll

如果您使用非 TS 版本,请记住更正 dll 的名称。

重新启动 Apache 并检查phpinfo();. 现在应该有gmagick块了。。

B)要纠正您的代码问题:

  1. Gmagick 构造函数不期望路径作为参数,而是完整的图像文件名(可能包含路径)。大多数情况下,最好将其留空并在readImage()调用中提供文件。
  2. 尝试一个完整的 $path (从根开始)并在 and 中使用readImage()writeImage()

这是一段工作代码的示例:

<?php
// assuming this is the path to your code and to your image files
$path = 'C:\xampp\htdocs\junk\imgproc\';

$image = new Gmagick();
$file = 'img1.jpg';
$image->readImage($path.$file);

// The rest of your code does not make any use of the GM instance, 
// so I add something functional here: create a grayscale version and show it
$fileOut= 'img1_GRAY.jpg';
$image->setImageType(Gmagick::IMGTYPE_GRAYSCALE);
$image->writeImage($path.$fileOut);
$image->destroy();
echo "<img src='$fileOut' >";
?>

它应该显示图像文件的灰度版本。

于 2012-09-18T12:55:32.623 回答