2

My environment is: MacOSX 10.8.3, PHP 5.3.17, ImageMagick 6.8.0, Apache 2.2.22

I have installed ImageMagick and PHP-Imagick module by using macports.

ImageMagick works as expected, for example I can convert a JPG to GIF by using the console command convert /my-path/file.jpg file.gif.

However when I create a new Imagick instance by using a sample code as follow:

<?php
  $m = new Imagick('/my-path/file.jpg');

I get the exception:

NoDecodeDelegateForThisImageFormat `/my-path/file.jpg' @ error/constitute.c/ReadImage/550

The format of the file doesnt change the result; I tested different JPG, GIF and PNG images however same exception occurs.

So I suspect, the PHP/Apache - ImageMagick integration part is somewhat faulty.

I saw this post on SO and applied the given resolution (adding the environment variable "MAGICKCODERMODULE_PATH" with the value "/opt/local/lib/ImageMagick-6.8.0/modules-Q16/coders") however that didn't make sense for my case. (I confirmed the existence of this environment variable from my phpinfo)

Outputs of some commands on my system:

I will appreciate any suggestion.

Apache Configuration, Environment and PHPImagick Configuration

Community
  • 1
  • 1
Lashae
  • 1,372
  • 1
  • 20
  • 36

2 Answers2

4

Solution

chmod 755 /opt

Insight and Thoughts

At last. I managed to solve the problem.

As there were no answers and suggestions on SO; I'm not suprised that something not expected was causing it!..

@sathia suggested to define an environment variable to call ImageMagick binaries. However in my case, I need to use phpImagick extension and access ImageMagick through its API, so this suggestion didn't make sense.

But I wanted to give it a try and call ImageMagick's convert binary by using PHP's system function. After calling it, I got a return value of "126"; and 126 means, binary is found however it's not executable!..

I checked the binary in /opt/local/bin/convert and it has appropriate execute permissions, then I checked /opt/local/bin and /opt/local directories as well and they were executable too. However the catch was /opt folder's permission was 700!

I managed to execute chmod 755 /opt and magically error has gone.

Lashae
  • 1,372
  • 1
  • 20
  • 36
1

I've been there too, this is how I solved it:

<?php    

    define("IMAGE_MAGICK_PATH","/usr/local/bin/");
    $in = '/my-path/file.jpg';
    $out = '/my-path/file.gif';
    $convertString = IMAGE_MAGICK_PATH." convert ".$yourfile." ".$out;
    exec($convertString);

hope it helps

sathia
  • 2,192
  • 2
  • 24
  • 42
  • 1
    Sorry but I don't think this is a solution. I want to use php-imagick extension, which provides a valuable API to ImageMagick. However, you suggest me to bypass php-imagick and call ImageMagick directly, this is not an alternative. – Lashae Jul 19 '13 at 11:22
  • I understand that. if I were you I'd test this API inside a linux box. I too work on a mac, but I use virtual machine in order to be as close as possible to the actual server configuration. wasting time making API work on a dev system is time stolen to actual production. In my humble opinion of course – sathia Jul 19 '13 at 11:56
  • Sathia, you are right. However, since everything works same on my development machine; setting up a virtual machine just for this error seems to be overkill. – Lashae Jul 19 '13 at 12:20
  • http://www.vagrantup.com/ reads: Run a single command — "vagrant up" — and sit back as Vagrant puts together your complete development environment. Say goodbye to the "works on my machine" excuse as Vagrant creates identical development environments for everyone on your team. in your case it was the opposite: doesn't work on my machine :) – sathia Jul 19 '13 at 12:43
  • Thank you @sathia, I know vagrant. However I'll try to fix this error ;) – Lashae Jul 19 '13 at 12:53