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

Reading without clipping

Oct 2, 2013 at 11:46 PM

It seems that whenever there is a clipping path (8bim) in the input file, any image information outside this path just disappears and comes out white. I've tried many things, like disabling Alpha, looking around in the ReadSettings class, setting ClipMask to null, setting the BackgroundColor.Alpha property to 0x0000 or 0xFFFF, but nothing seems to work.

Is there a way to get around this (rather destructive) behaviour?

I'm using Magick.NET-

Thank you,
Oct 3, 2013 at 6:19 AM
Can you post a code example and a link to an input image? If you don't want to put you image online feel free to contact me trough codeplex and e-mail it to me.
Oct 3, 2013 at 10:13 AM
Hi dlemstra,

Well, the code is now narrowed down to this:
using (MagickImage img = new MagickImage(@"C:\Temp\clippingpath.eps"))
    img.Format = MagickFormat.Tiff;
    img.CompressionMethod = CompressionMethod.Zip;

using (MagickImage img = new MagickImage(@"C:\Temp\path.eps"))
    img.Format = MagickFormat.Tiff;
    img.CompressionMethod = CompressionMethod.Zip;
The images:

clippingpath.eps contains a path, which is a clipping path. path.eps contains a path, but it's not even a clipping path.
Somehow, for both files, the same problem happens: you lose all the image information outside the path area, even when the path isn't a clipping path. It would be nice if the information was preserved and then you could clip it yourself like you can with -clip on the ImageMagick command line; or, if that isn't supported yet, it should ignore the paths altogether? :)

Thanks for looking into it!

Oct 3, 2013 at 10:46 AM
Have you tried to determine if this was an ImageMagick or a GhostScript problem? Which version of Ghostscript did you install?

Do you get the same result when you save the file in another format, e.g. PNG?
Oct 3, 2013 at 11:41 AM
Edited Oct 3, 2013 at 11:46 AM
Yes, I've done some more testing this morning.

Using GSview (you can download it from the same Ghostscript website), opening up clippingpath.eps will also show the areas around the clipping path to be erased (so the same "problem", but this might be expected from a viewing-only application).
However, when you open path.eps, the area is preserved. This means that GSview correctly identifies the difference between a clipping path and a regular path and that it -does- have the ability to tell Ghostscript to ignore it.

ImageMagick (the command-line binary) will ignore all paths, regardless whether or not it is a clipping path, unless you decide to manually do things with -clip or -clip-path. This means that ImageMagic takes it into account or at least instructs Ghostscript to ignore the paths. Whether or not it correctly identifies the difference between a clipping path and a regular path, I don't know (haven't tested it, but you can specify which path to use with -clip-path, even when it's not a clipping path). I assume that using -clip or -clip-path will make ImageMagick do its own internal rendering of the path and this will not go through Ghostscript again, so that has little to do with it.

Magick.NET however, always clips using any kind of path (or Ghostscript does). Also when you save it as PNG or use .ToBitmap(): it's always the same result.

Perhaps the instruction for Ghostscript on how to parse the file is dfferent between the ImageMagick application and Magic.NET library. It's just a guess.

P.S. I've tried Ghostscript 9.05 x86 and 9.10 x64: the same result on all tests.

Thanks again,
Oct 3, 2013 at 10:06 PM
When I run ImageMagick from the command line I am getting the same result as with your example. I am using the following command:
convert path.eps path.png
If your images are different then please put up a link so I can see the difference. Maybe there is an option that tells ghostscript to preserve the data outside the clipping path?
Oct 7, 2013 at 9:44 AM
Hi dlemstra,

Yes, you're right.

It turns out that this is a Photoshop issue. When saving the file as EPS with a clipping path, it will not only store PostScript instructions for the bitmap and the clipping path, but it will also store some instructions that draws the clipping path and then sets the background colour around it to 0. It is simply part of the image itself.

When I delete all paths from the 8bim resources (Any ID's in the range of 2000-2999) and open the file in Photoshop, the path is gone from the list of paths and the bitmap is entirely visible. When I read the same file in ImageMagick, the clipping path is still visible. So the question is: how does Photoshop know which PS instructions to ignore. Maybe it ignores them all, except for the bitmap instruction.

Either way, it's not an ImageMagick problem.

Thanks for looking into it. :)