skip to Main Content

We have many square EPS images, which we would like to export via script to PNG at very specific formats/sizes, namely

  • 8192×8192, greyscale, no alpha, no anti-aliasing
  • 2048×2048,greyscale, no alpha, anti-aliased.

We have had no luck scripting the “professional” tools Photoshop or Illustrator to do this (although we can do so through the UI, their weak scripting support does not give control over alpha or precise image export size, so we either always get alpha in the large images, or we sometimes get slightly inaccurate image sizes which breaks subsequent algorithms.)

Our first attempt at doing the high resolution version of this was:

gs -sDEVICE=pnggray -o cover.png -dDEVICEWIDTHPOINTS=8192 -dDEVICEHEIGHTPOINTS=8192 -dGraphicsAlphaBits=1 -dPDFFitPage=true cover.eps

However, this does not seem to resize the image to fill the box as expected.

Is there a way, given a square EPS, to get Ghostscript to do what we want?

2

Answers


  1. Chosen as BEST ANSWER

    Do not accidentally specify PDFFitPage in the command line above. Specify EPSFitPage when dealing with EPS files. PDFFitPage will silently do nothing.


  2. Your problem with EPS files is that they do not request a media size. That’s because EPS files are intended to be included in other PostScript programs, so they need to be resized by the application generating the PostScript.

    To that end, EPS files include comments (which are ignored by PostScript interpreters) which define the BoundingBox of the EPS. An application which places EPS can quickly scan the EPS to find this information, then it sets the CTM appropriately in the final PostScript program it is creating and inserts the content of the EPS.

    The FitPage switch in Ghostscript relies on having a known media size (and you should set -dFIXEDMEDIA when using this) and a requested media size, figuring out what scale factor to apply to the request in order to make it fit the actual size, and setting up the CTM to apply that scaling.

    If you don’t ever get a media size request (which you won’t with an EPS) then no scaling will take place.

    Now Ghostscript does have a different switch, EPSCrop which picks up the comments from the EPS and uses that to set the media size (Ghostscript has mechanisms to permit processing of comments for this reason, amongst others). You could implement a similar mechanism to pick up the BoundingBox comments, and scale the EPS so that it fits a desired target media size.

    I could probably knock something up, but I’d have to mess around creating an example file to work from…..

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search