Search code examples
phpimageimage-processingimagemagickidentify

identifyImage() in Imagemagick resetting connection in PHP?


I've come across an odd problem with the following code:

$image = new Imagick($real_location); 
$ident = $image->identifyImage(); 
$format = $ident['colorSpace'];

In most cases, this is fine. But on some photos it resets the connection and basically makes it look like the page has timed out.

An example photo is a JPG at 72dpi, 3008x2000, EXIF data included, RGB, 8Bit-channel.

If i run it like below, its fine:

exec("identify -format %r  ".$real_location,$output);

However, i would perfer to stay away from exec() and try to stick to the library if possible.

I had a look through my PHP error logs and came across the following:

httpd: magick/option.c:1264: GetImageOption: Assertion `image_info != (ImageInfo *) ((void *)0)' failed.
[Mon Mar 26 15:40:26 2012] [notice] child pid 1582 exit signal Aborted (6)

Solution

  • I did some further investigation and what I was trying to do is check if an image is CMYK. I found that the following code fixed my reason, but doesn't fix the error:

    $image = new Imagick($real_location);
    $ident = $image->getImageColorspace();  
    if($ident ==  Imagick::COLORSPACE_CMYK) {
    
    }