Search code examples
pngghostscripteps

Using GhostScript to export PNGs at fixed size


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

  • 8192x8192, greyscale, no alpha, no anti-aliasing
  • 2048x2048,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?


Solution

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