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.

Imagick version: ImageMagick-6.7.6-3-Q16-windows-dll. Module is working. I can see imagick in 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:

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

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

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

$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

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.

Thank You in advance

filip.karas
  • 596
  • 2
  • 11
  • 27
  • What is your question? Can you not use `$_SERVER['DOCUMENT_ROOT']`? – Ben Carey Mar 31 '12 at 09:56
  • Is this only Imagick problem? Can you do `echo __DIR__` and check if it is not your working directory? – dev-null-dweller Mar 31 '12 at 10:27
  • 1
    Ben: my question is, how to make imagick to use current directory (D:\web\i) as working directory instead of apache root directory (C:\Program Files (x86)\Apache24\) (as it was working in older PHP versions) – filip.karas Mar 31 '12 at 11:33
  • dev-null-dwaller: it is only imagick issue: output of echo __DIR__ is D:\Web\i (D:\web is apache http root, i is folder where test srcipt and a.jpg are located) – filip.karas Mar 31 '12 at 11:34
  • @BenCarey: I can use __ DIR __ . 'a.jpg' and it's working. I'm just trying to find out, if there is a way how to make it work without the __ DIR __. All my imagick srcipts are written using relative paths (like ../images/x.jpg) and in PHP5.4 this is no loonger working. So I'm wondering if there is a way how to make it work again. – filip.karas Mar 31 '12 at 11:41
  • @user1112626 - in that case you should fill in bug report https://bugs.php.net/report.php and provide some info about your php/apache/imagick version. – dev-null-dweller Mar 31 '12 at 12:14
  • Just wanted to chime in and announce that this same thing is happening to me on Windows 7 w/Apache and PHP 5.3. Maybe unrelated to PHP and more related to the DLL – Funktr0n Feb 13 '14 at 14:26

1 Answers1

10

Sounds like you might have unearthed a bug.

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

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

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

$im = new imagick (__DIR__ . DIRECTORY_SEPARATOR . 'a.jpg');
GordonM
  • 31,179
  • 15
  • 87
  • 129
  • 2
    thank you, this workaround is working. actually, the better way (for me) is realpath('a.jpg'); it's working without any problems. i was just trying to figure out, if someone else had similar problem. i tried 2 different php_imagick.dll (i'm not able to compile it by myself under windows) and 4 different Imagick versions (installers) but i think this is not the real problem, because with absolute paths imagick is working fine. – filip.karas Mar 31 '12 at 15:24