Announcement

  •  » Engine
  •  » ImageMagick instead of GD, CMYK and AdobeRGB issues

#1 2010-09-28 14:59:46

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

ImageMagick instead of GD, CMYK and AdobeRGB issues

Hi coding team,

You may already know that Piwigo uses the GD library to resize photos and create thumbnails. The overall quality is nice BUT there is a major issue: GD removes the EXIF/IPTC metadata.

An elegant solution is to use ImageMagick instead of GD to resize photos, even if ImageMagick is not available everywhere!

I've been working on ImageMagick and the first results are really good: ImageMagick is slightly faster than GD and you can get a better result at quality level.

The problem is about colorspaces/colorprofiles.

1) if the photo uses the AdobeRGB colorprofile, then it would be better to convert it to a sRGB profile for perfect display on 100% browsers/OS. Unfortunately I don't know how to detect the "Adobe RGB" profile with enough reliability. So I currently decide to keep the color profile as it is (the display is a bit "flat" on my Linux box with AdobeRGB photos)

2) if the photo uses the CMYK colorspace:

2.a) if the color profile is embedded into the photo file, then we simply convert it to a standard sRGB color profile + sRGB colorspace

2.b) if the color profile is not embedded into the photo file, ImageMagick only creates a big mess at color level if we try to convert to sRGB color profile and we can't apply a random CMYK color profile because it will produce random colors. In this case, I see no other solution than displaying an error "your photos are defined in the CMYK color space but the color profile is missing from the file".

Note: in the 2.b case, we could keep the colorspace CMYK as it is but it means that Internet Explorer users won't see the photos :-/, which is worse than displaying an error, in my opinion.

Offline

 

#2 2010-12-21 22:14:39

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: ImageMagick instead of GD, CMYK and AdobeRGB issues

Today I'm implementing ImageMagick into Piwigo and I'm really wondering how to solve the CMYK problem.

To avoid being stopped on this issue, I decide to work the same way as pLoader currently does : no try to detect/convert color spaces and profiles. The thing is that GD is pretty good at converting from CMYK to sRGB without specific command.

The problem is that for the 0.01% of users who will send photos saved in CMYK mode, their photos won't be visible in Internet Explorer.

Offline

 

#3 2010-12-21 22:16:20

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: ImageMagick instead of GD, CMYK and AdobeRGB issues

As a note for myself when I will try to perform colorprofile conversions:

Code:

  // echo '<pre>'; print_r($image->getImageProfiles('icc')); echo '</pre>'; exit();
  // echo '<pre>'; print_r($image->getImageProfiles()); echo '</pre>'; exit();

  $cs = $image->getImageColorspace();
  if ($cs == Imagick::COLORSPACE_CMYK)
  {
    // TODO throw an error or continue?
    
    print "Image is CMYK<br/>\n";
    // $cmyk = file_get_contents('/home/pierrick/Desktop/CMYK_Profile.icm');
    // $cmyk = $image->getImageProfiles('icc');
    // echo '<pre>'.$cmyk['icc'].'</pre>'; exit();
    // $image->profileImage('icc', $cmyk['icc']);
    

    // $srgbPath = '/home/pierrick/Desktop/sRGB_v4_ICC_preference.icc';
    
    $srgbPath = '/usr/share/ImageMagick-6.5.7/config/sRGB.icm';
    $srgb = file_get_contents($srgbPath);
    $image->profileImage('icc', $srgb);
    $image->negateImage(false);
    // $image->stripImage();
    $image->setImageColorspace(Imagick::COLORSPACE_SRGB);
    // $image->stripImage();
    // $image->setImageFormat('jpeg');
  }

Offline

 
  •  » Engine
  •  » ImageMagick instead of GD, CMYK and AdobeRGB issues

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact