Issues with reading EPS image after upgrading to 7.0.0.0013

Apr 24, 2015 at 10:45 AM
Hi, after upgrading from 7.0.0.0009 to 7.0.0.0013 my EPS image becomes blank.

I use iTextSharp to generate a PDF, and until now I got a page with text and an Image.

This is my code for reading the image from disk (path = location to file):
var settings = new MagickReadSettings { Density = new PointD(density * 100, density * 100), ColorSpace = ColorSpace.CMYK };
                using (var mi = new MagickImage(path, settings))
                {
                    mi.ColorSpace = ColorSpace.GRAY;
                    mi.Format = MagickFormat.Png;
                    return Image.GetInstance(mi.ToByteArray());
                }
When I downgrade to an earlier version it starts working again.

This is the error message I get in my log file:
2015-04-24 12:43:19 - Warning: Error when loading vector image : Typography.GUI.vshost.exe: PostscriptDelegateFailed `The system cannot find the file specified.
' @ error/ps.c/ReadPSImage/951 (Typography.Core.TypographyHelper)

I'm using the x86 build of ImageMagick and I have GhostScript 9.15 (x86) installed on the system.

Any Ideas?
Coordinator
Apr 24, 2015 at 11:21 AM
It looks like the execution of Ghostscript fails. Can you provide me with some detailed debug information? You can find information on how to get that here: https://magick.codeplex.com/wikipage?title=Detailed%20debug%20information. If you don't want to share this information publicly or if it is to spammy to post here then please contact me through CodePlex.
Apr 24, 2015 at 12:29 PM
dlemstra wrote:
It looks like the execution of Ghostscript fails. Can you provide me with some detailed debug information? You can find information on how to get that here: https://magick.codeplex.com/wikipage?title=Detailed%20debug%20information. If you don't want to share this information publicly or if it is to spammy to post here then please contact me through CodePlex.
Hi, that is my assumtion as well, it seems like I don't always catch the PostscriptDelegateFailed exception in my log but the image always turns out a white square in the same size as the image should be.

I recorded the trace from Magick.Net when generating the single PDF page, it's 33658 lines so I uploaded it in a text-file here: http://www.filedropper.com/magicknet-trace.

I also tried to upgrade GhostScript, but it din't make any difference, tried a few different versions of Magick.Net and in the version the dll was splitted in 3 parts with the wrapper the image started appearing as a white box insted of the actual image.
Coordinator
Apr 24, 2015 at 2:01 PM
Edited Apr 24, 2015 at 6:02 PM
Does this happen for every eps file? And can you provide me with one of the files to test with? Maybe the exception is only for one of the images that fails. I just tried to convert one of my eps files to png and it work perfectly. Maybe CMYK is the problem?

EDIT: Contact me through CodePlex if you don't want to publicly share your image.
Apr 27, 2015 at 7:15 AM
Edited Apr 27, 2015 at 8:48 AM
EDIT: Thought I solved it by changing the color space, but it turns out the contrast was off (images turned out to gray-ish) and I still got this error in the logs: Error when loading vector image : Typography.GUI.vshost.exe: PostscriptDelegateFailed `The system cannot find the file specified.
' @ error/ps.c/ReadPSImage/951

Once I switched back to the older library anch changed back the color spaces the problem went away (no warnings, good contrast).

This change allows me to see the picture: Lokks good in test app (image is written to disk), but not in the actual app where the image is added to a pdf:
var settings = new MagickReadSettings { Density = new PointD(density * 100, density * 100), ColorSpace = ColorSpace.GRAY};
                using (var mi = new MagickImage(path, settings))
                {
                    // not needed anymore mi.ColorSpace = ColorSpace.GRAY;
                    mi.Format = MagickFormat.Png;
                    return Image.GetInstance(mi.ToByteArray());
                }
Apr 27, 2015 at 7:46 AM
Edited Apr 27, 2015 at 8:44 AM
I built a small Windows Forms application to test the image conversion and the result looks just fine (after changing he color space).

My investigation so far:
  • The images looks fine in older version
  • The same code produces a white square (no image) in new version
  • After changing the color space the image looks fine in test application with new version
  • After changing the color space the image looks washed out in real application with new version (might be caused by iTextSharp after changing the color space of the image)
Regarding the exception:

The exceptions is thrown from the line:
var mi = new MagickImage(path, settings);
This method is called upon only if (File.Exists(path)) so the error message "`The system cannot find the file specified.
' @ error/ps.c/ReadPSImage/951" should not refere to the image file, event though it looks like it.

It seems like this error only occurs when severeal threads are working simultaneously, whick makes it kind of interesting since it works fine in the older version.

After some more testing I can clearly se a pattern that the never version of Magick.NET have issues with multi-threading.
The exception above ONLY occurs when trying calling new MagickImage(path, settings) from more than one thread.

Callstack:
 ImageMagick.MagickDelegateErrorException: Typography.GUI.vshost.exe: FailedToExecuteCommand `"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" -g3389x1335 -dEPSCrop  "-sOutputFile=C:/Users/A045408/AppData/Local/Temp/magick-1348Hxy6ICAUNRYj%d" "-fC:/Users/A045408/AppData/Local/Temp/magick-1348VQD-x3Xpy-8x" "-fC:/Users/A045408/AppData/Local/Temp/magick-1348uscbvgqUp7aR"' (The system cannot find the file specified.
) @ error/delegate.c/ExternalDelegateCommand/481
   --- End of inner exception stack trace ---
   at ImageMagick.Wrapper.MagickImage.HandleException(MagickException exception)
   at ImageMagick.Wrapper.MagickImage.Read(String fileName, MagickReadSettings readSettings)
   at ImageMagick.MagickImage.Read(String fileName, MagickReadSettings readSettings)
   at ImageMagick.MagickImage.Read(FileInfo file, MagickReadSettings readSettings)
   at ImageMagick.MagickImage..ctor(FileInfo file, MagickReadSettings readSettings)
   at Typography.Core.TypographyHelper.GetVectorImage(String path, Single density) in c:\Projects\SEMAL-TypoGraphy\Typography.Core\TypographyHelper.cs:line 539}
Coordinator
Apr 29, 2015 at 6:50 AM
We continued this conversion by e-mail and we figured out what was happening. I made a mistake when I split up the library in 3 libraries. The embedded delegates.xml file could not be read and this caused an issue when reading EPS files in a multi-threaded environment. This problem will be fixed in the next release of Magick.NET that I will try to publish later this week.
Apr 29, 2015 at 7:08 AM
I can confirm that this issue was fixed in a new build and I'm looking forward to it being published for everyone to take advantage of it.
Apr 29, 2015 at 1:34 PM
Did the issue apply only to multi-threading with EPS files or multi-threading in general? The ideal implementation for this for me is a parallel scenario.
Coordinator
Apr 29, 2015 at 2:22 PM
Edited Apr 29, 2015 at 2:24 PM
This issue applies to files that require Ghostscript (e.g. Pdf/Eps/Ps) in a multi-threaded environment.