28th Aug 2009
How to rotate a goddamned eps file
I routinely have to produce vector graphics as EPS files, for figures in conference papers. Usually I compose these things as a slide in Apple’s Keynote, and choose “save as Postscript” from the Print menu. This gets me a big white field, with the figure lurking within. It must be rotated and cropped.
One of the great embarrassments of the computer industry is that you can’t simply rotate and crop a picture in one of the world’s most common image formats. Other embarrassments include the increasing difficulty of plugging a computer into a projector, and the industry decision to put rental movies on exposed, scratchable plastic platters. The EPS problem is less of a scandal, but it is still pretty bad. You want to look at an image, rotate, crop and save it; pretty much every OS could do that out of the box since the 1980s—to a raster image. To do the same with a vector graphic you need to dig up and download a raft of decades-old utilities, and pore through a few support forums along the way.
I eventually figure out a byzantine way to fix these pictures, but it is completely different for each computer system I’ve ever used. If you found this page by Google search, I can give you a working solution for OSX; if this is not your system, I can only wish you luck.
First, the ugly setup. I have Ghostscript and LaTeX installed on my computer, which give me the commands I need to manipulate Postscript files. You can get LaTeX here, and for Ghostscript you go to this page. Download and open the most recent distribution, navigate to its folder in the Terminal, and type the commands ./configure, make, and sudo make install. Making ghostscript requires that you have the compiler installed; if you get a command not found when typing gcc at the Terminal prompt, then you need to dig out your install disk and install the optional Xcode tools.
To crop, I start out with a printer output start.ps on OSX, and distill the thing from a PS file into an EPS file using the Terminal command eps2eps start.ps nextStep.eps. This also tidies up the file; if you don’t do this first, the other commands will eventually get confused.
Step 1.5: open the EPS file with a text editor, and delete the third line that starts “HiResBoundingBox.” This is redundant information, and if you leave it in, you will eventually have two different bounding boxes.
Next, I use ./psfixbb -c -e nextStep.eps > stepThree.eps to fix the bounding box. You can find this script online, and it invokes Ghostscript to work. Psfixbb renders the picture as a raster image, scans that image to find the nonwhite pixels, and estimates the true bounding box of your graphic.
[It supposedly has an option to rotate the picture too, but it doesn't work. It will rotate the bounding box and leave the graphic alone.]
Finally, if you must rotate the image use epsffit -r NUM NUM NUM NUM stepThree.eps stepFour.eps. Replace those four NUMs with the four numbers spit out by the previous program. This program manages to rotate EPS files properly under OSX.
I routinely have to produce vector graphics as EPS files, for figures in conference papers. Usually I compose these things as a slide in Apple’s Keynote, and choose “save as Postscript” from the Print menu. This gets me a big white field, with the figure lurking within. It must be rotated and cropped.
One of the great embarrassments of the computer industry is that you can’t simply rotate and crop a picture in one of the world’s most common image formats. Other embarrassments include the increasing difficulty of plugging a computer into a projector, and the industry decision to put rental movies on exposed, scratchable plastic platters. The EPS problem is less of a scandal, but it is still pretty bad. You want to look at an image, rotate, crop and save it; pretty much every OS could do that out of the box since the 1980s—to a raster image. To do the same with a vector graphic you need to dig up and download a raft of decades-old utilities, and pore through a few support forums along the way.
I eventually figure out a byzantine way to fix these pictures, but it is completely different for each computer system I’ve ever used. If you found this page by Google search, I can give you a working solution for OSX; if this is not your system, I can only wish you luck.
First, the ugly setup. I have Ghostscript and LaTeX installed on my computer, which give me the commands I need to manipulate Postscript files. You can get LaTeX here, and for Ghostscript you go to this page. Download and open the most recent distribution, navigate to its folder in the Terminal, and type the commands ./configure, make, and sudo make install. Making ghostscript requires that you have the compiler installed; if you get a command not found when typing gcc at the Terminal prompt, then you need to dig out your install disk and install the optional Xcode tools.
To crop, I start out with a printer output start.ps on OSX, and distill the thing from a PS file into an EPS file using the Terminal command eps2eps start.ps nextStep.eps. This also tidies up the file; if you don’t do this first, the other commands will eventually get confused.
Step 1.5: open the EPS file with a text editor, and delete the third line that starts “HiResBoundingBox.” This is redundant information, and if you leave it in, you will eventually have two different bounding boxes.
Next, I use ./psfixbb -c -e nextStep.eps > stepThree.eps to fix the bounding box. You can find this script online, and it invokes Ghostscript to work. Psfixbb renders the picture as a raster image, scans that image to find the nonwhite pixels, and estimates the true bounding box of your graphic.
[It supposedly has an option to rotate the picture too, but it doesn't work. It will rotate the bounding box and leave the graphic alone.]
Finally, if you must rotate the image use epsffit -r NUM NUM NUM NUM stepThree.eps stepFour.eps. Replace those four NUMs with the four numbers spit out by the previous program. This program manages to rotate EPS files properly under OSX.
Posted in Uncategorized | Comments Off