Thursday, January 21, 2010

Convert PS and EPS files into JPEG

I got this useful information from this link.

You can convert any ps or eps file into a jpeg using ghostscript:

gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=myfile.jpg myfile.eps


This method has one flaw. It produces huge files. Depending on the eps file you may get something like 2000×3000 pixels which is slightly on the insane side. Also the file size of the JPG will be about 10 times that of the eps.
We will now need to trim and resize the file using some Image Magic tools:


mogrify -trim -resize 800x600 myfile.jpg


In order to execute this command on multiple files,  use following bash script

for k in $(ls *.eps); do b=`basename ${k%.eps}`; gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=$b.jpg $k; mogrify -trim -resize 800x600 $b.jpg; done
 

1 comment:

Hassan said...

That was really helpfull