如何在 Windows Vista 上安装 php 的 gmagick 扩展

发布于 2024-12-23 01:07:08 字数 1033 浏览 4 评论 0原文

gmagick 是 imagemagick 的新版本,具有更多功能集,它的资源密集度较低且速度快,但问题是网上关于这个出色工具的讨论很少,我最近在 http://devzone.zend.com/1559/manipulated-图像-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\junk\imgproc\imgproc1.php:4 中未捕获异常“GmagickException”,并显示消息“无法打开文件 (gallery/img1.jpg)”: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 中抛出

gmagick is newer version of imagemagick with more set of features it is less resource intensive and fast but the problem is there is very few discussion about this wonderful tool on web i recently came across this on
http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/
but i could not install it on windows machines cos phpize did not work so i tried some other way and some how managed to get on phpinfo page but i could not make it work further i colud not even open a single image with gmagick
this is code i used

     <?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/>';
   ?>

i used this code to instanstiate gmagick class and open image but i am geeting very big error as follows
Fatal error: Uncaught exception 'GmagickException' with message 'Unable to open file (gallery/img1.jpg)' in C:\xampp\htdocs\junk\imgproc\imgproc1.php:4 Stack trace: #0 C:\xampp\htdocs\junk\imgproc\imgproc1.php(4): Gmagick->__construct('gallery/img1.jp...') #1 {main} thrown in C:\xampp\htdocs\junk\imgproc\imgproc1.php on line 4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2024-12-30 01:07:08

A) 回答标题中的问题(可能会引导其他读者来这里):

PHP GraphicsMagick 扩展的 Windows 版本可以在此处获取:
http://valokuva.org/builds/

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

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

extension=php_gmagick_ts.dll

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

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

B) 要纠正代码问题:

  1. Gmagick 构造函数不需要路径作为参数,而是完整的图像文件名(可能包括路径)。大多数情况下,最好将其留空并在 readImage() 调用中提供文件。
  2. 尝试使用完整的 $path(从根开始)并在 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' >";
?>

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

A) To answer the question in your headline (that might lead other readers here):

Windows builds of the GraphicsMagick extension for PHP can be obtained here:
http://valokuva.org/builds/

Check whether you need the thread-safe version or not by looking at a phpinfo(); output of your webserver. Look for the entry Thread Safety. In the entry PHP Extension Build you should also find the VC version that you need, e.g. API20090626,TS,VC9 for VC9.

Download the latest build that matches your conditions, put it into your PHP/ext directory and add it to your php.ini like this:

extension=php_gmagick_ts.dll

Remember to correct the name of the dll if you use the non-TS version.

Restart Apache and check phpinfo();. There should be a gmagick block now..

B) To correct the problem with your code:

  1. The Gmagick constructor does not expect a path as a parameter, but a full image filename (may include a path). Most often it is better to leave it empty and provide the file in the readImage() call.
  2. Try a full $path (starting at root) and use it in readImage() and writeImage():

Here is an example of a working piece of code:

<?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' >";
?>

It should show a grayscale version of your image file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文