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类和打开图像,但是我遇到了非常严重的错误:在C:\xampp\htdocs\htdocs\imgproc\imgpro1.php:4堆栈跟踪:#0:\xampp\htdocs\imgproc\imgpro1.php(4):Gmagick->_(construct/img1.jp.) #1 {main}抛入C:\xampp\htdocs\imgproc\imgpro1.php(4):Gmagick->_(construct/img1.jp.‘)#1{main}抛入C:\xampp\htdocs\imgproc\imgpro1.php(4):Gmagick->_( exception /img1.jp.’)#1{main}抛入C:\xampp\htdocs\imgproc\imgpro1.php(4):Gmagick->_(exception/img1.jp.‘)#1{main}.
发布于 2012-09-18 12:55:32
( A)回答标题中的问题(这可能会导致其他读者):
GraphicsMagick扩展for PHP的Windows构建可以在这里获得:http://valokuva.org/builds/
通过查看need服务器的phpinfo();输出,检查是否需要线程安全版本。查找条目Thread Safety。在条目PHP Extension Build中,您还应该找到所需的VC版本,例如API20090626,TS,VC9 for VC9。
下载符合条件的最新版本,将其放到PHP/ext目录中,然后按如下方式添加到php.ini中:
extension=php_gmagick_ts.dll如果使用非TS版本,请记住更正dll的名称.
重新启动Apache并检查phpinfo();。现在应该有一个gmagick块了。
B)来纠正代码中的问题:
readImage()调用中提供文件。下面是一个工作代码的示例:
<?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' >";
?>它应该显示图像文件的灰度版本。
https://stackoverflow.com/questions/8643574
复制相似问题