|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61583 Imagick extension does not work with relative paths
Submitted: 2012-03-31 15:32 UTC Modified: 2016-02-08 13:41 UTC
Avg. Score:4.1 ± 0.9
Reproduced:16 of 17 (94.1%)
Same Version:11 (68.8%)
Same OS:9 (56.2%)
From: filip dot karas at gmail dot com Assigned: danack
Status: Assigned Package: imagick (PECL)
PHP Version: 5.4.0 OS: Windows 7
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-03-31 15:32 UTC] filip dot karas at gmail dot com
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 (C:\Program Files 
(x86)\Apache24\ in my case) instead of php file location as reference.

Test script:
This is NOT working

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

This is working

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

(assumming a.jpg is in the same directory as .php file)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-26 19:05 UTC] nick at moc10media dot com
I had the exact same problem, but in PHP 5.3.10 on Windows 7. I can see it fine in phpinfo(), and I go to run a script passing the relative path of an image file to Imagick, and it crashes.

I did not use to have this problem until I upgraded to IM 6.7.6. So that leads me to believe that the issue is either with IM or the IM PHP extension? Any thoughts?
 [2013-12-03 11:31 UTC]
-Assigned To: +Assigned To: mkoppanen
 [2014-01-21 11:39 UTC] tomkrawc at gmail dot com

It was reported in the past. See

I'm not sure but this exception suggests it is not an Imagick's but ImageMagick's problem. 

If it could be fixed it would be great cause on Linuxes relative paths are working.

 [2014-01-21 13:50 UTC]
Hello, what is the return value of getcwd in your script?
 [2014-01-21 14:07 UTC] tomkrawc at gmail dot com
getcwd() returns D:\wamp\www\imagick

In this directory I have examples from imagick and image file.
 [2015-04-01 17:20 UTC]
-Assigned To: mkoppanen +Assigned To: danack
 [2015-04-01 17:20 UTC]
Assigning to myself to investigate.
 [2015-12-18 14:01 UTC]
-Summary: Imagick PHP 5.4 extension does not work with relative paths +Summary: Imagick extension does not work with relative paths -Type: Bug +Type: Feature/Change Request
 [2015-12-18 14:01 UTC]
There isn't going to be a perfect solution. Imagick can pass things that are not valid filenames to ImageMagick, and this greatly confuses the PHP virtual directory.

For example `new Imagick("foo.pdf[2]")` would load the 3rd page of a PDF as a single image, but it is not a valid filename.
 [2016-02-07 18:12 UTC] lee dot traynor at skeptic dot de
Realpath () returns an ordinary ANSI/ISO string but Imagick requires this to be in UTF-8, so if there are any unusual characters in the path, this has to be converted first:

$im = new Imagick (utf8_encode (realpath ("some_file.jpg")));
 [2016-02-08 13:41 UTC]
Lee, if you are seeing an issue with utf8 chars, please open a separate issue. 

What you are seeing is very unlikely to be related to this one.
PHP Copyright © 2001-2016 The PHP Group
All rights reserved.
Last updated: Sat Feb 13 19:01:39 2016 UTC