Losing transparency with CMYK

Oct 28, 2014 at 11:50 PM
Edited Oct 29, 2014 at 12:02 AM
I have this file located here:

https://www.dropbox.com/s/4aa0pkptw1yfpsz/cartoon_network_logo_r.eps?dl=0

What I am trying to do is take an .eps image and convert it to .png. It does it, but the resulting image loses transparency while maintaining the true black color(000000) in the image. If I change the color space to be RGB when reading the image, it loses the true black color but maintains transparency. The black is a shade or two off. My goal is to convert the image while maintaining transparency and the true black color.
    var destinationStream = new FileStream(@"C:\test.png", FileMode.Create);

    //this is the image in dropbox
    string sourceFilePath = sourceFile;

    MagickReadSettings settings = new MagickReadSettings();
    //settings.ColorSpace = ColorSpace.RGB;

    MagickImage magickImage1 = new MagickImage(sourceFilePath, settings);

    magickImage1.Strip();

    magickImage1.Format = MagickFormat.Png;


    destinationStream.SetLength(0);

    magickImage1.Write(destinationStream);
Thanks
Coordinator
Oct 29, 2014 at 6:26 AM
This was also reported in this topic: https://magick.codeplex.com/discussions/570506. At this moment it is not possible but I will take a look at it when I have a couple days off at the end of the year.
Oct 29, 2014 at 12:08 PM
Cool. Thanks
Dec 3, 2014 at 9:07 PM
Not a rush in any way, but do you have an possible ETA as to when you might be able to take a look at this particular issue.
Coordinator
Dec 9, 2014 at 4:12 PM
I will take a look at this again when I am back home next week.
Coordinator
Dec 26, 2014 at 2:08 AM
I tried to see if the image contains an alpha channel with Ghostscript but it looks like your image does not seem to contain an alpha channel:
D:\Images\eps>"C:\Program Files\gs\gs9.15\bin\gswin64c.exe" -q -dQUIET -dSAFER -
dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=
2 "-sDEVICE=tiffsep" "-r72x72" -g297x80 -dEPSCrop -dPrintSpotCMYK=true  "-sOutpu
tFile=test.tiff" "-fcartoon_network_logo_r.eps"
%%SeparationColor: "Cyan" 100% ink = 32760 0 0 0 CMYK
%%SeparationColor: "Magenta" 100% ink = 0 32760 0 0 CMYK
%%SeparationColor: "Yellow" 100% ink = 0 0 32760 0 CMYK
%%SeparationColor: "Black" 100% ink = 0 0 0 32760 CMYK
Ghostscript will draw the text on a transparent background when you set the ColorSpace to RGB. Ghostscript does not do that for CMYK images. I did however manage to accomplish what you want with the following trick/work-around:

string sourceFilePath = @"D:\images\eps\cartoon_network_logo_r.eps";

// Read as CMYK
using (MagickImage cmyk = new MagickImage(sourceFilePath))
{
  MagickReadSettings settings = new MagickReadSettings();
  settings.ColorSpace = ColorSpace.sRGB;

  // Read as RGBA
  using (MagickImage rgba = new MagickImage(sourceFilePath, settings))
  {
    // Copy alpha channel from RGBA to CMYK image
    cmyk.Composite(rgba, Gravity.Center, CompositeOperator.CopyAlpha);

    cmyk.Write(@"D:\test.png");
  }
}
There is only one problem with the example, it does not work with the current release of Magick.NET due to a bug. You will have to wait till the next release or contact me to get a development build.
Dec 26, 2014 at 2:30 AM
That's great work on your part. And thanks for your time on this. I will not be able to play around with this until probably around the second/third week of January so I am in no huge rush. Quick question:

When you say that my image does not contain an alpha channel, does that mean:
  1. that it should? do most CMYK images contain an alpha channel? I'm more of a developer and not an true image guy so there are pieces that I miss.
  2. if it did contain an alpha channel, would this not be an issue?
Thanks, and Happy Holidays.
Coordinator
Dec 26, 2014 at 2:46 AM
timpeters wrote:
  1. that it should? do most CMYK images contain an alpha channel? I'm more of a developer and not an true image guy so there are pieces that I miss.
I don't think it should contain an alpha channel. But I have no good answer to your other question. It's the same question as if you where asking me if most images contain an alpha channel. I don't know the answer. There are CMYK images that have an alpha channel (CMYKA) and CMYK images that don't have an alpha channel.

timpeters wrote:
  1. if it did contain an alpha channel, would this not be an issue?
Then we would have to figure out how we can extract the alpha channel with Ghostscript from a CMYK image. Our current code does not support CMYKA images, it just threats them as CMYK.
Dec 26, 2014 at 3:05 AM
Ah. I think I get it now. Thanks. You've been extremely helpful. Any idea as to when your next full release will be? No rush on my part. Your current release is working very well for us right now.
Coordinator
Dec 26, 2014 at 9:51 AM
The next release will probably be at the end of January.
Jan 26, 2015 at 12:48 PM
Are you still slated for a release at the end of January to cover the above issue/workaround?
Coordinator
Jan 26, 2015 at 9:47 PM
I just published the new release :)