Gaius Coffey
Gaius Coffey

Reputation: 53

Can ImageMagick detect missing and non-embedded fonts in EPS files?

We have an upload service based on Java and ImageMagick to generate required assets as appropriate for inclusion in generated documents.

But...

When a user uploads an EPS (or similar) that references non-embedded fonts, rather than throw an error, ImageMagick simply substitutes the fonts with something of its own devising.

This means:

  1. The user gets a shock when their logos look utterly unrecognisable
  2. We get a render error when the print software complains it doesn't know what font to use

So...

Is there any way to get ImageMagick to report on unembedded fonts and/or any alternative that would allow us to interrogate uploaded EPS files to locate missing fonts?

Upvotes: 1

Views: 359

Answers (1)

Kurt Pfeifle
Kurt Pfeifle

Reputation: 90263

The most reliable way to get this info is running Ghostscript directly and look at its output.

I say to run it "directly" because ImageMagick does run it anyway when you have it process your EPS input. (ImageMagick cannot work with EPS, PS, or PDF inputs -- so it exploits Ghostscript as its delegate to produce the initial image raster data which it then takes over for further processing).

So you could do this for example (command syntax is for Linux, Unix or Mac OS X) :

gs   -o /dev/null    -sDEVICE=pdfwrite unembedded-font-used.eps

On Windows you would run it like this:

gswin64c.exe -o nul  -sDEVICE=pdfwrite unembedded-font-used.eps

Ghostscript would then report this output in the terminal, for example. Here the first lines:

GPL Ghostscript GIT PRERELEASE 9.18 (2015-04-07)
Copyright (C) 2015 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Can't find (or can't open) font file %rom%Resource/Font/ArialMT.
Can't find (or can't open) font file ArialMT.
Can't find (or can't open) font file %rom%Resource/Font/ArialMT.
Can't find (or can't open) font file ArialMT.
Querying operating system for font files...

Now the next lines, in case of no "good enough" substitute font is found:

Error: /typecheck in /findfont
Operand stack:
   Arial
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   1919   1   3   %oparray_pop
Dictionary stack:
   --dict:1190/1684(ro)(G)--   --dict:0/20(G)--   --dict:78/200(L)--
Current allocation mode is local
GPL Ghostscript GIT PRERELEASE 9.18: Unrecoverable error, exit code 1

This second part looks a bit different, if Ghostscript finds a font to use in place of the missing one:

Loading NimbusSanL-Reg font from %rom%Resource/Font/NimbusSanL-Reg... 4674144 3087974 1934432 636034 1 done.

There may be multiple lines like this. You will be able to see exactly which font file Ghostscript will use. In the above case, it will use a font it has built into its executeable, which is indicated by the %rom% part of the output. In case the font was found on the local disk, it will tell the full path.

Just be aware of an additional detail: Part of the above output will be targeted at <stdin> and the other part at <stdout>. In above example it is all mixed together, because I copied it from my terminal. You'll have to take the appropriate measures yourself as needed if you want to only see <stderr>.


Of course you could produce the final PNG, TIFF or JPEG output directly with Ghostscript too. That is, unless you require ImageMagick to do more sophisticated processing afterwards.

Upvotes: 1

Related Questions