This project has moved and is read-only. For the latest updates, please go here.

Transparency/image background

Jul 15, 2014 at 4:20 PM
Edited Jul 15, 2014 at 4:39 PM
Is there a way to maintain the background color of an image? My overall goal is to take an image that has a transparent background and make sure that the transparent background stays when converting to .png. It seems as if Magick is changing the transparent background to white during the conversion.
Jul 16, 2014 at 6:06 AM
Can you post a small code sample and a link to an image so I can reproduce this issue? The background should not just suddenly change to white.
Jul 16, 2014 at 2:00 PM
Edited Jul 16, 2014 at 2:01 PM
I was trying to find an image where the above issue was occurring but I came across a different error using the following image. I have ghostscript installed.

I get a "MagickDelegateErrorException" on the following line:

MagickImage magickImage = new MagickImage(sourceFilePath);
Jul 16, 2014 at 2:55 PM
I can read the eps file without any problems. What is your Ghostscript version? I am using 9.14.
Jul 17, 2014 at 3:07 PM
Edited Jul 17, 2014 at 3:08 PM
I was unable to upgrade to 9.14 but I was able to upgrade from 9.09 to 9.10 and I am now past my eps issue and back to my original issue. I'm unable to download 9.14 from the ghostscript site. It keeps timing out. So I'm on 9.10, which seems to work fine for me

Using that image link above, and using the following code, the resulting .png has a white background. Are able to verify this as well?
        string sourceFilePath = "eps file";
        MagickImage magickImage1 = new MagickImage(sourceFilePath);
The original has a transparent background but the resulting .png has a white background.
Jul 17, 2014 at 3:46 PM
I am seeing places where, when using the imagemagick command lines, they were able to get around this by setting "background" to none when reading a file. That might be the correct solution but I'm just not sure how to set "background" to none using
Jul 17, 2014 at 7:48 PM
Edited Jul 17, 2014 at 9:54 PM
Your eps file is a CMYKA file. This is not supported by Ghostscript. You can read the image with transparency if you specify the colorspace as sRGB before reading the image:
MagickReadSettings settings = new MagickReadSettings();
settings.ColorSpace = ColorSpace.sRGB;
using (MagickImage magickImage1 = new MagickImage(sourceFilePath, settings))
Jul 17, 2014 at 8:54 PM

Does this ghostscrpit thing apply to files that are not CMYKA? Also, is ColorSpace.sRGB the answer for all files or just this one? And is the real solution for me to determine what the colorspace is for a given file, and then set settings.ColorSpace to that prior to reading that file?
Jul 18, 2014 at 5:47 AM
You are changing the color space of the image with this option. If you don't have eps images that you want to keep CMYK you can safely set it to sRGB for all your eps files.
Jul 18, 2014 at 12:06 PM
If I did want to keep an .eps file as CMYK, does that mean I would be unable to maintain transparency?
Jul 18, 2014 at 12:25 PM
You cannot convert an eps file to another format and keep it CMYK without loosing transparency.
Jul 18, 2014 at 12:27 PM
Does the same apply to .ai files as well?
Jul 18, 2014 at 12:43 PM
You are correct, you have this problem with all file formats that require Ghostscript (AI/EPS/PDF/PS).
Jul 18, 2014 at 3:37 PM
And I think I already know the answer to this, but is there a way to determine if a file has a transparent background before I force it's color space to change? I'm assuming no.
Jul 18, 2014 at 7:18 PM
Edited Jul 18, 2014 at 7:54 PM
I don't know how I can determine if an eps file has a transparent background. But what is your output format, it might not matter.
Jul 18, 2014 at 7:37 PM
My output format for maintaining transparency is .png.
Jul 18, 2014 at 7:55 PM
But png does not support CMYK. What is your output format when the image is CMYK?
Jul 18, 2014 at 8:08 PM
Ah. I did not know that .png did not support CMYK. That was the part I was missing. I apologize for any confusion on my part. My knowledge of image colors is light.

I've been tasked with making sure that any .eps or .ai file that is converted to .png maintains its transparency. But I think you answered my concerns with your last reply. If someone wants to convert to .png then CMYK would not matter if their main goal is maintaining transparency.

I think I'm fixed now. Thanks for your time/effort on this.