2
0

ps_to_png.sh 913 B

12345678910111213141516171819202122232425262728
  1. #! /bin/bash
  2. # Written by Ryan Schmidt. Oct 4, 2008
  3. # render postscript at this magnification, then scale back down to get antialiasing
  4. aafactor=4
  5. # add a border of this many pixels around final image
  6. border=4
  7. scale() {
  8. echo $1 | awk -F x -v scale=$2 '{printf("%.0fx%.0f", $1 * scale, $2 * scale)}'
  9. }
  10. # compute inverse of aafactor for use with pamscale whose -reduce option seems broken
  11. aafactorinv=$(echo "scale=4; 1/$aafactor" | bc)
  12. # convert scale factor so it gives 96-dpi output instead of 72-dpi output
  13. scale=$(echo "scale=4; $aafactor*96/72" | bc)
  14. # compute bounding box of initial rendering
  15. bb=$(scale $(grep PageBoundingBox $1 | awk -f sz.awk) $scale)
  16. # compute resolution at which to render
  17. res=$(scale 72x72 $scale)
  18. # render it
  19. gs -sDEVICE=ppmraw -g$bb -r$res -sOutputFile=- -dNOPAUSE -q $1 -c showpage -c quit | pnmcrop | pamscale $aafactorinv | pnmmargin -white $border | pnmtopng > $2