Hi, regarding to old versions, I can tell you that the hoster holds 3 different (major) versions:
Code: Select all
Pfad zu ImageMagick 4.2.9: /usr/bin/ImageMagick_4.2.9/ (für Typo3)
Pfad zu ImageMagick 5.5.4: /usr/bin/
Pfad zu ImageMagick 6.2.6: /usr/bin/ImageMagick_6.2.6/bin/
But the named 6.2.6 actually is the 6.6.9 versions I have to use.
For now we have solved it in that way that we only use the ICC-conversion method if the user has manually enabled it. This may be changed after we have collected more informations about usable versions.
But also I have had some quirks code. Before, I have used mixed functions: individual ICC-conversion and some from the more generic color management. That must have screwed up the images. The newer ImageMagick versions indeed seem to be more fault-tolerant by handling inaccurate code.
GOOD WORK GUYS!
So, on the
6.6.9 server the ICC-conversion now is working fine.
The basic conversion only need to be enhanced to support cmyk too. But we are glad to have the first working version of our new module.
I post the code here, if someone is interested. It is a part from our new module, so not working out of the box, but hopefully a good starting point:
Code: Select all
// start image magick
$this->im = new Imagick();
// should we use the ICC-CMS ?
$this->useCMS = $this->data['useCMS'] ? true : false;
// set the working colorspace: COLORSPACE_RGB or COLORSPACE_SRGB ( whats about COLORSPACE_GRAY ??)
$this->workspaceColorspace = $this->useCMS ? Imagick::COLORSPACE_RGB : Imagick::COLORSPACE_SRGB;
$this->im->setColorspace($this->workspaceColorspace);
// load the image
if(!$this->im->readImage($this->destFilename)) { // actually we get a filecopy from origFilename to destFilename from PageImage
$this->release();
throw new WireException(sprintf(__("Imagick cannot load imagefile: %s", basename($this->destFilename))));
return false;
}
// check validity against image magick
if(!$this->im->valid()) {
throw new WireException(sprintf(__("loaded file '%s' is not a valid image", basename($this->destFilename))));
return false;
}
// get image format
$this->imageFormat = $this->im->getImageFormat();
// check validity against PW
if(!in_array($this->imageFormat, $this->validSourceImageFormats())) {
throw new WireException(sprintf(__("loaded file '%s' is not in the list of valid images", basename($this->destFilename))));
return false;
}
// check and retrieve different image parts and information: ICC, Colorspace, Colordepth, Metadata, etc
$this->imageColorspace = $this->im->getImageColorspace();
$this->workspaceColorspace = IMAGICK::COLORSPACE_GRAY == $this->imageColorspace ? IMAGICK::COLORSPACE_GRAY : $this->workspaceColorspace;
$this->im->setColorspace($this->workspaceColorspace);
$this->imageMetadata = $this->im->getImageProfiles('*');
if(!is_array($this->imageMetadata)) $this->imageMetadata = array();
$this->hasICC = array_key_exists('icc', $this->imageMetadata);
$this->hasIPTC = array_key_exists('iptc', $this->imageMetadata);
$this->hasEXIF = array_key_exists('exif', $this->imageMetadata);
$this->hasXMP = array_key_exists('xmp', $this->imageMetadata);
$this->imageType = $this->im->getImageType();
$this->imageDepth = $this->im->getImageDepth();
// remove not wanted / needed Metadata
foreach(array_keys($this->imageMetadata) as $k) {
if('icc'==$k) continue; // we keep embedded icc profiles
if('iptc'==$k) continue; // we keep embedded iptc data
if('exif'==$k && $this->data['keepEXIF']) continue; // we have to keep exif data too
if('xmp'==$k && $this->data['keepXMP']) continue; // we have to keep xmp data too
$this->im->profileImage("$k", null); // remove this one
}
$this->im->setImageDepth(16);
if($this->useCMS) {
$this->useCMS = $this->iccCmsStart();
}
// now do all manipulations here ...
// manipulations are finished, prepare for saving
if($this->useCMS) {
$this->iccCmsFinish();
}
$this->im->setImageDepth(($this->imageDepth > 8 ? 8 : $this->imageDepth));
// should we strip ICC-Profiles?
if(!$this->data['keepICC']) {
$this->im->setImageProfile('icc', null);
}
$this->im->setImageFormat($this->imageFormat);
$this->im->setImageType($this->imageType);
if(in_array(strtoupper($this->imageFormat), array('JPG', 'JPEG'))) {
$this->im->setImageCompressionQuality($this->quality);
$this->im->setImageCompression(IMAGICK::COMPRESSION_JPEG);
}
else {
$this->im->setImageCompressionQuality($this->quality);
}
// save to file
if(!$this->im->writeImage($this->destFilename)) {
$this->release();
return false;
}
return true;
The methods for the icc-conversions are:
Code: Select all
protected function iccCmsStart() {
if(!$this->useCMS) {
return false;
}
// check if we have an ICC Workspaceprofile and a RGB-Targetprofile
$tmpName = dirname(__FILE__) . '/icc/targetprofiles/' . $this->data['rgbOutProfile'];
if(is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccRgbOut = file_get_contents($tmpName);
}
$this->useICC = isset($this->iccRgbOut) ? true : false;
$tmpName = dirname(__FILE__) . '/icc/workspaceprofiles/' . $this->data['workspaceProfile'];
if($this->useICC && is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccWorkspace = file_get_contents($tmpName);
}
else {
$this->useICC = false;
}
unset($tmpName);
$this->useGray = false;
if($this->useICC && $this->hasICC) {
if(IMAGICK::COLORSPACE_GRAY == $this->imageColorspace) {
$tmpName = dirname(__FILE__) . '/icc/grayscaleprofiles/' . $this->data['grayOutProfile'];
if(is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccGrayOut = file_get_contents($tmpName);
}
unset($tmpName);
$this->useGray = isset($this->iccGrayOut) ? true : false;
}
#$this->im->profileImage('icc', $this->imageMetadata['icc']); // that profile is the embedded one from the image, seems we don't need to process that here
$this->im->profileImage('icc', $this->iccWorkspace);
$this->im->setImageColorspace(Imagick::COLORSPACE_RGB);
return true;
}
elseif($this->useICC && !$this->hasICC) {
if(in_array($this->imageColorspace, array(IMAGICK::COLORSPACE_SRGB, IMAGICK::COLORSPACE_RGB))) {
$tmpName = dirname(__FILE__) . '/icc/targetprofiles/' . $this->data['rgbInProfile'];
if(is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccRgbIn = file_get_contents($tmpName);
}
if(!isset($this->iccRgbIn)) {
$tmpName = dirname(__FILE__) . '/icc/workspaceprofiles/' . $this->data['rgbInProfile'];
if(is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccRgbIn = file_get_contents($tmpName);
}
}
if(isset($this->iccRgbIn)) {
$this->im->profileImage('icc', $this->iccRgbIn); // assign the RGB default profile
$this->im->profileImage('icc', $this->iccWorkspace);
return true;
}
}
elseif(IMAGICK::COLORSPACE_CMYK == $this->imageColorspace) {
$tmpName = dirname(__FILE__) . '/icc/cmykprofiles/' . $this->data['cmykInProfile'];
if(is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccCmykIn = file_get_contents($tmpName);
$this->im->profileImage('icc', $this->iccCmykIn); // assign the default cmyk profile
$this->im->profileImage('icc', $this->iccWorkspace);
return true;
}
}
elseif(IMAGICK::COLORSPACE_GRAY == $this->imageColorspace) {
$tmpName = dirname(__FILE__) . '/icc/grayscaleprofiles/' . $this->data['grayOutProfile'];
if(is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccGrayOut = file_get_contents($tmpName);
}
$this->useGray = isset($this->iccGrayOut) ? true : false;
$tmpName = dirname(__FILE__) . '/icc/grayscaleprofiles/' . $this->data['grayInProfile'];
if($this->useGray && is_file($tmpName) && 'icc'==strtolower(pathinfo($tmpName, PATHINFO_EXTENSION))) {
$this->iccGrayIn = file_get_contents($tmpName);
$this->im->profileImage('icc', $this->iccGrayIn); // assign the default grayscale profile
$this->im->profileImage('icc', $this->iccWorkspace);
return true;
}
}
}
return false;
}
protected function iccCmsFinish() {
if(!$this->useCMS) return false;
if(!$this->useICC) return false;
// transition into Targetcolorspace
if($this->useGray) {
$this->im->profileImage('icc', $this->iccGrayOut);
}
else {
$this->im->profileImage('icc', $this->iccRgbOut);
}
}