Struggling to install Imagick php extension [SOLVED]

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
vinny38
Posts: 5
Joined: 2016-04-12T02:35:33-07:00
Authentication code: 1151

Struggling to install Imagick php extension [SOLVED]

Post by vinny38 »

Hi all,
I can't figure out how to install Imagick php extension on my local Apache Server.

I use EasyPHP 14.1
PHP version is 5.5.8

I did install ImageMagick 6.9.3-8 Q8 x64, seems to work fine.

Then I downloaded php_imagick-3.1.2-5.5-ts-vc11-x86 package from https://pecl.php.net/package/imagick/3.1.2/windows

Then copied php_imagick.dll file to C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\ext
and copied CORE...dll files to C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\apache\bin

Finally I added 'extension=php_imagick.dll' into my php.ini file

I also installed Ghostscript 9.19

At this point, all seems fine.
The EXEC console 'identify -list format' command line returns many formats, including pdf.

Now, let's test the IM extension:

Code: Select all

<?php 
$imagick = new Imagick($_SERVER['DOCUMENT_ROOT']  .'/projects/mypath/test-imagick.pdf'); 
$imagick->readImage($_SERVER['DOCUMENT_ROOT'] .'/projects/mypath/test-imagick.pdf'); 
$imagick->writeImages($_SERVER['DOCUMENT_ROOT']  .'/projects/mypath/convertedtestimagick.jpg', false); 
?>
Then, I got this :

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'NoDecodeDelegateForThisImageFormat `C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb/projects/caue-mypath/test-imagick.pdf' @ error/constitute.c/ReadImage/555' in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\mypath\test.php:10 Stack trace: #0 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\mypath\test.php(10): Imagick->__construct('C:/Program File...') #1 {main} thrown in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\mypath\test.php on line 10
:( :( :(

Could someone tell me where I got it wrong?
Thanks in advance for your help

Vinny
Last edited by vinny38 on 2016-04-25T02:41:47-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Struggling to install Imagick php extension

Post by snibgo »

When PHP fails in calls IM to convert from PDF, a common solution is to adjust delegates.xml so ghostscript has the full path.
snibgo's IM pages: im.snibgo.com
vinny38
Posts: 5
Joined: 2016-04-12T02:35:33-07:00
Authentication code: 1151

Re: Struggling to install Imagick php extension

Post by vinny38 »

Hi snigbo...
thanks for your answer.

How exactly would you do that??

Besides, I find strange that phpinfo() shows no supported format for IM :
Image

Cheers
vinny38
Posts: 5
Joined: 2016-04-12T02:35:33-07:00
Authentication code: 1151

Re: Struggling to install Imagick php extension

Post by vinny38 »

In addition:

Image
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Struggling to install Imagick php extension

Post by Bonzo »

Imagemagick is an external program and is unlikely to show up in the phpinfo output.

Have you tried Imagick on a different type of file e.g jpg to try and isolate the problem?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Struggling to install Imagick php extension

Post by snibgo »

vinny38 wrote:In addition:
Yes, so ImageMagick run from the command line can find Ghostscript. But when it is run from PHP, perhaps it can't.
snibgo's IM pages: im.snibgo.com
vinny38
Posts: 5
Joined: 2016-04-12T02:35:33-07:00
Authentication code: 1151

Re: Struggling to install Imagick php extension

Post by vinny38 »

Have you tried Imagick on a different type of file e.g jpg to try and isolate the problem?
OK, i tried a very basic

Code: Select all

<?php 
$imagick = new Imagick($_SERVER['DOCUMENT_ROOT']  .'/projects/mypath/image.jpg'); 
$imagick->readImage($_SERVER['DOCUMENT_ROOT'] .'/projects/mypath/image.jpg'); 
?>
and the exception "NoDecodeDelegateForThisImageFormat" is thrown again

I feel like I missed something obvious...:?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Struggling to install Imagick php extension

Post by Bonzo »

I am not an Imagick expert but I do not know why you have the image path twice.

I would now try something even more simple - an image in the same folder as the code.

I know this code worked for me:

Code: Select all

$im = new Imagick('image.jpg');
$im->blurImage( 4, 3 );
$im->writeImage('blured.jpg');
$im->destroy();
tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

Re: Struggling to install Imagick php extension

Post by tk1 »

[b]@vinny38[/b] I see two problems in your installation. You are mixing quantum Q8 (ImageMagick) and Q16 (PHP Imagick). On the pecl site there are only Q16 versions.
Also you should have equal bit versions of PHP and its extensions x64 (PHP Imagick).

If you copy CORE*.dll files to the Apache/PHP directory then You don't need to install ImageMagick cause libraries contain all you need.

I don't copy CORE*.dll files to the Apache/PHP but I set MAGICK_HOME system variable to tell Imagick where libraries are located. Bit versions are equal for IM and Imagick and PHP of course.
cheers
tk1
vinny38
Posts: 5
Joined: 2016-04-12T02:35:33-07:00
Authentication code: 1151

Re: Struggling to install Imagick php extension

Post by vinny38 »

@tk1
Hi tk1!
Ok I unistalled everything and followed your instructions from scratch.
I didn't copy CORE*.dll files, and...
everything works fine now!

Thanks for your help! :D
Post Reply