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.
shmk
Posts: 3 Joined: 2011-01-28T08:47:01-07:00
Authentication code: 8675308
Post
by shmk » 2011-01-28T08:59:42-07:00
I'm trying to convert a RGB .gif to a CMYK .gif using IMagick.
I've wrote this piece of code
Code: Select all
$i = new Imagick('mosaique.gif');
$i->setImageColorspace(Imagick::COLORSPACE_CMYK);
$i->setImageFormat('gif');
$i->writeImage('mosaique-cmyk.gif');
But the resultant "mosaique-cmyk.gif" still a RGB... but with inverted colors
EXAMPLE FILES ATTACHED!
What am I doing wrong?
Attachments
CMYK mosaique-cmyk.gif (11.2 KiB) Viewed 18304 times
RGB mosaique.gif (11.2 KiB) Viewed 18304 times
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2011-01-28T14:02:00-07:00
does gif support cmyk? try jpg
shmk
Posts: 3 Joined: 2011-01-28T08:47:01-07:00
Authentication code: 8675308
Post
by shmk » 2011-01-29T09:09:26-07:00
fmw42 wrote: does gif support cmyk? try jpg
I've tried with a jpg
Code: Select all
$i = new Imagick('mosaique.jpg');
$i->setImageColorspace(Imagick::COLORSPACE_CMYK);
$i->setImageFormat('jpg');
$i->writeImage('mosaique-cmyk.jpg');
it's converted to CMYK but it is likes in negative
Attachments
CMYK mosaique-cmyk.jpg (158.64 KiB) Viewed 18283 times
RGB mosaique.jpg (189.7 KiB) Viewed 18283 times
shmk
Posts: 3 Joined: 2011-01-28T08:47:01-07:00
Authentication code: 8675308
Post
by shmk » 2011-01-31T08:29:36-07:00
An important update!
I've tried to run my script making a .pdf on another server and it works fine.
Are there any known bug in IMagick?
Are there some options to set in the php5 library?
The version that returns me the inverted image is newer than the one that works correctly
WRONG RESULT
PHP 5.3.3
IMagick 3.0.0RC1
ImageMagick 6.6.2
CORRECT RESULT
PHP 5.2.10
IMagick 2.1.1
ImageMagick 6.5.1
kevin.florida
Posts: 1 Joined: 2013-06-15T08:56:18-07:00
Authentication code: 6789
Post
by kevin.florida » 2013-06-15T08:59:49-07:00
I HAVE A SOLUTION!
After 2 days of hacking and intensive research I have solved the problem. It was a very frustrating issue, so I wanted to make sure I share the solution.
Note: my Imagick object is $jpeg and you have to download the adobe AdobeRGB1998.icc profile from their website (do a google search).
Only on 5.3.x you have to negate the converted image, see my solution:
Code: Select all
$range = $jpeg->getQuantumRange();
$php_vs_arr = preg_split("/\./", phpversion());
$php_vs = $php_vs_arr[0] . '.' . $php_vs_arr[1];
if ($jpeg->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
//make sure cmyk color-space is set correctly
$jpeg->setImageColorspace(12);
// then we add an RGB profile
$icc_rgb = file_get_contents(FRAMEWORK_PATH . DS . 'color' . DS . 'AdobeRGB1998.icc');
$jpeg->profileImage('icc', $icc_rgb);
unset($icc_rgb);
//set color space to rgb
$jpeg->setImageColorspace(13);
//fix gamma, hue, saturation, brightness
if($php_vs < 5.3) {
//ADJUST GAMMA BY 2.0 for 5.2.x
$jpeg->levelImage(0, 2.0, $range['quantumRangeString']);
} else {
//php 5.3 hack FOR INVERTED COLORS
$jpeg->negateImage(false, Imagick::CHANNEL_ALL);
}
}
$jpeg->stripImage();
//end convert to RGB=========================|