Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagick PHP 5.4 extension does not work with relative paths. (windows)

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

like image 731
filip.karas Avatar asked Mar 31 '12 09:03

filip.karas


People also ask

How do I enable ext imagick?

To enable Imagick for your website, go to your Site Tools -> Dev -> PHP Manager. Click the PHP Extensions tab and find the entry for the “imagick” extension in the list that appears. Then click the Change value button (pencil icon), select the On radio button for Status and save the changes.

Is imagick and ImageMagick same?

ImageMagick is a PHP utility, a command line tool for image manipulation. For further details, see this. Imagick is an API or a class that performs the function same as ImageMagick. It provides numerous functions for image manipulation in PHP.


1 Answers

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');
like image 148
GordonM Avatar answered Nov 15 '22 13:11

GordonM