Imagick PHP 5.4扩展不适用于相对路径。 (视窗)

时间:2022-09-06 13:26:14

I'm trying to install imagick PHP extension on windows. It was working on PHP 5.2, PHP 5.3 but I have problems with PHP 5.4.

我正在尝试在Windows上安装imagick PHP扩展。它正在开发PHP 5.2,PHP 5.3但我遇到了PHP 5.4的问题。

Imagick version: ImageMagick-6.7.6-3-Q16-windows-dll. Module is working. I can see imagick in phpinfo().

Imagick版本:ImageMagick-6.7.6-3-Q16-windows-dll。模块正在运行。我可以在phpinfo()中看到想象力。

The problem is, that imagick does not recognize relative path to files. For example, if I have simple index.php and a.jpg in the same folder, I can't use $im = new imagick('a.jpg'); because I get exception:

问题是,imagick无法识别文件的相对路径。例如,如果我在同一个文件夹中有简单的index.php和a.jpg,我就不能使用$ im = new imagick('a.jpg');因为我得到例外:

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `a.jpg': No such file or directory @ error/blob.c/OpenBlob/2614' in D:\Web\i\index.php:3 Stack trace: #0 D:\Web\i\index.php(3): Imagick->__construct('a.jpg') #1 {main} thrown in D:\Web\i\index.php on line 3

致命错误:未捕获异常'ImagickException',消息'无法打开图像`a.jpg':D:\ Web \ i \ index.php中没有这样的文件或目录@ error / blob.c / OpenBlob / 2614:3堆栈跟踪:#0 D:\ Web \ i \ index.php(3):Imagick - > __ construct('a.jpg')#1 {main}在第3行的D:\ Web \ i \ index.php中抛出

But when I use absolute path $im = new imagick('D:\web\i\a.jpg'); it is working.

但是当我使用绝对路径时,$ im = new imagick('D:\ web \ i \ a.jpg');这是工作。

I found out, that Imagick is using Apache core dir as reference. I saved the image without path:

我发现,Imagick使用Apache核心目录作为参考。我没有路径保存图像:

$im->writeImage( 'this-is-what-im-looking-for.jpg' );

$ im-> writeImage('this-is-what-im-looking-for.jpg');

And I found it in C:\Program Files (x86)\Apache24\this-is-what-im-looking-for.jpg

我在C:\ Program Files(x86)\ Apache24 \ this-is-what-im-looking-for.jpg中找到它

The problem is, that all my old scripts are written with relative paths and I would like to countinue using them.

问题是,我所有的旧脚本都是用相对路径编写的,我想用它们来计算。

I don't know, if the problem is in imagick itself, or somewhere in PHP 5.4.

我不知道,如果问题出在想象本身,或者PHP 5.4中的某个地方。

Thank You in advance

先谢谢你

1 个解决方案

#1


10  

Sounds like you might have unearthed a bug.

听起来你可能已经发现了一个bug。

I'd suggest reporting it at http://bugs.php.net/report.php

我建议在http://bugs.php.net/report.php上报告

In the meantime, you could work around it by using __DIR__ or __FILE__ to construct an absolute path.

在此期间,您可以使用__DIR__或__FILE__来构建绝对路径。

For example, to use the script's directory, do the following:

例如,要使用脚本的目录,请执行以下操作:

$im = new imagick (__DIR__ . DIRECTORY_SEPARATOR . 'a.jpg');

#1


10  

Sounds like you might have unearthed a bug.

听起来你可能已经发现了一个bug。

I'd suggest reporting it at http://bugs.php.net/report.php

我建议在http://bugs.php.net/report.php上报告

In the meantime, you could work around it by using __DIR__ or __FILE__ to construct an absolute path.

在此期间,您可以使用__DIR__或__FILE__来构建绝对路径。

For example, to use the script's directory, do the following:

例如,要使用脚本的目录,请执行以下操作:

$im = new imagick (__DIR__ . DIRECTORY_SEPARATOR . 'a.jpg');