1

I read through the usage documentation, and could not find any way to output an image X pixels wide, with the height determined by the aspect ratio. I have a large amount of EPS files I need to rasterize, and they need to be at least 2400px wide. My current workaround is to set a usually-high-enough resolution using the -r flag, but this makes many of the images much, much larger than I need them to be.

I am currently using this command:

gs -dNOPAUSE -sDEVICE=pngalpha -dEPSCrop -sOutputFile=./result.png -r500x500 -dEPSFITPAGE -dBATCH -dQUIET ./input.eps

I have experimented with different combinations and settings of -g, -dDEVICEWIDTH, -dDEVICEHEIGHT, -dFIXEDMEDIA, -dFIXEDRESOLUTION, and -dFitPage, however I could not figure it out.

I have a feeling there may be some kind math needed to simply set the correct value for -r that will yield the desired dimensions, but I'm not sure how to go about this. Any help appreciated!

Julien
  • 5,243
  • 4
  • 34
  • 35

1 Answers1

1

You cannot specify (from the command line) anything which will modify one dimension and make the other dimension rescale.

You can do this by programming in PostScript. Media size requests are processed by setpagdevice, you can either redefine setpagedevice so that i preprocesses the media size request or create a BeginPage procedure which modifies the media size.

Redefining setpagedevice is probably simplest. Write a routine which examines the requested width and height, and the current value of HWResolution. Compare that with a known target value (which can be stored in a PostScript dictionary using -d= if required. Calculate the required scale factor and apply it to both the requested width and height, alter the requested values appropriately and pass these to the original setpagedevice definition.

This also precludes any requirement to set DEVICEWIDTHPOINTS, DEVICEHEIGHTPOINTS or FIXEDMEDIA.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • I tried looking into PostScript, however I could not find succinct guides or tutorials that contain the relevant information, except for [this monstrous pdf reference guide](https://www.adobe.com/products/postscript/pdfs/PLRM.pdf) by Adobe. I also found [this answer](http://stackoverflow.com/a/10024458/441212), but I don't know what's really going on in the code. What is the best resource I can use to learn how to do the things you just described? – Julien Oct 06 '15 at 15:03
  • That's my answer and you don't want that. PostScript is a programming language, if you want to do anything constructive with it, I'm afraid you will have to learn at least some of the language. The PLRM may look large but its pretty compact for a complete language, and its very well written. You can search SO for other answers involving BeginPage, I'm reasonably sure you'll find some from me, possibly others. I would recommend John Deubert's Acumen Training (http://www.acumentraining.com/acumenjournal.html) site for guides to PostScript. July 2001 has an article on using BeginPage and EndpPage – KenS Oct 06 '15 at 15:11
  • Thanks Ken. I'll look into your suggested resources. – Julien Oct 06 '15 at 15:39