php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61583 Imagick extension does not work with relative paths
Submitted: 2012-03-31 15:32 UTC Modified: 2016-12-20 22:49 UTC
Votes:18
Avg. Score:4.1 ± 0.9
Reproduced:16 of 18 (88.9%)
Same Version:11 (68.8%)
Same OS:9 (56.2%)
From: filip dot karas at gmail dot com Assigned: danack (profile)
Status: Wont fix Package: imagick (PECL)
PHP Version: 5.4.0 OS: Windows 7
Private report: No CVE-ID: None
 [2012-03-31 15:32 UTC] filip dot karas at gmail dot com
Description:
------------
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)


Patches

Pull Requests

History

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] mike@php.net
-Assigned To: +Assigned To: mkoppanen
 [2014-01-21 11:39 UTC] tomkrawc at gmail dot com
Guys!

It was reported in the past. See https://bugs.php.net/bug.php?id=59594

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.

cheers
 [2014-01-21 13:50 UTC] mkoppanen@php.net
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] danack@php.net
-Assigned To: mkoppanen +Assigned To: danack
 [2015-04-01 17:20 UTC] danack@php.net
Assigning to myself to investigate.
 [2015-12-18 14:01 UTC] danack@php.net
-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] danack@php.net
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] danack@php.net
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.
 [2016-02-16 05:00 UTC] minhtho2611 at gmail dot com
Uncaught exception 'ImagickException' with message 'UnableToLoadModule `C:\xampp\apache\bin\IM_MOD_RL_TIFF_.dll': The specified procedure could not be found. @ error/module.c/OpenModule/1282' in D:\MinhTho\SNG\08_Sourcecode\PHP\admin\application\controllers\image.php:300 Stack trace: #0 

i want setting image tiff in xampp windows.thank you.
 [2016-03-01 22:32 UTC] danack@php.net
-Type: Feature/Change Request +Type: Documentation Problem
 [2016-03-01 22:32 UTC] danack@php.net
After having thought about this for a while - I'm not going to attempt to change it.

It is trivial to call realpath in userland, and pass absolute file names to Imagick.

Trying to handle things like "./SQTimetable.pdf[2]" which means open the 2nd page of the PDF as valid "file names" is absolutely not trivial - in fact I'm not sure how it could be handled. 

Rather than creating a whole load of work, just to solve something that already has a userland solution, I'm just going to update the documentation to be clearer that only absolute file names are supported.
 [2016-12-20 22:49 UTC] danack@php.net
-Status: Assigned +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 14:01:30 2024 UTC