CMYK Conversion works OK on Win32, but not Linux

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
OneFunk
Posts: 4
Joined: 2016-01-29T05:59:39-07:00
Authentication code: 1151

CMYK Conversion works OK on Win32, but not Linux

Post by OneFunk » 2016-02-01T03:00:16-07:00

I'm trying to write some PHP that will make a decent attempt at converting a CMYK image into an sRGB image

An example original CMYK image is...

Image

In chrome it looks far too bright.. It should look more like this...

Image

My code appears to work OK on my local WAMP development installation. However, when I run it on my linux server, the resulting image looks just like the original image. i.e. no conversion.

Running the convert command, manually on the command line, converts the image fine... So i think the profiles, and imagemagick are installed ok.

Code: Select all

$ convert cmyk2.jpg -profile sRGB.icc s.jpg

The code I have looks like this.... I'm not sure what's not working, and how to go about fixing this. Can you help?

Code: Select all

<?php
$dir = __DIR__;
$out = "rgb_output.jpg";

$img = new \Imagick($dir."/cmyk2.jpg");
if ($img->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
    $profiles = $img->getImageProfiles('*', false);
    echo "<br>"; var_export($profiles);

    $has_icc_profile = (array_search('icc', $profiles) !== false);
    if ($has_icc_profile === false) {
        echo "<br> $has_icc_profile === false";
        $icc_cmyk = file_get_contents($dir . '/profiles/USWebUncoated.icc');
        $img->profileImage('icc', $icc_cmyk);
        unset($icc_cmyk);
    }
    $icc_rgb = file_get_contents($dir . '/profiles/sRGB.icm');
    echo "<br>".strlen($icc_rgb);
    $img->profileImage('icc', $icc_rgb);
    unset($icc_rgb);

    $profiles = $img->getImageProfiles('*', false);
    echo "<br>"; var_export($profiles);

    //$img->stripImage(); // this will drop down the size of the image dramatically (removes all profiles)
    //$img->setImageColorspace(Imagick::COLORSPACE_RGB);

    if ($img->writeImage("$dir/$out")) {
        $profiles = $img->getImageProfiles('*', false);
        echo "<br>"; var_export($profiles);
        echo "<br>written ok <a target=_blank href='".$out."?rnd=".rand(11111,99999)."'>view the pic</a>";
    } else {
        echo "cant write";
    }
}
else {
    echo "Not a CMYK image";
}

Post Reply