Convert PS and EPS images to JPEG
The reason why I post stuff like this here is twofold. Firstly (is that even a word?), I forget. Chances are that in 3 months I will need this shit again, and won’t remember the exact syntax, or the name of the tool I used. So instead of googling for it, I can just search through my blog archives.
Secondly, chances are that there are quite a few intermediate or beginner latex users out there who may or may not find this useful.
Here is the scenario: you created a beautiful Latex document. In fact it is so awesome that someone approaches you and asks you to send them that incredibly cool chart or figure you used in your paper. So you send the person the eps/ps file and they can’t open it.
The proper raction that should be taken in such situation is of course repeatedly whacking said person on the head with a blunt object until they get a clue. Sadly forcible clue insertion is not always an option, so every once in a while you will need to convert your images into some more luser friendly format.
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 humongous 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
Obviously you can put your own dimension instead of the 800×600. Mogrify will resize the image, and also cut down the size of the file to a manageable level. Still, in most cases files obtained using this method were bigger than the eps files used to produce them. It’s best to simply use your photo editing tool (gimp?) and re-export the image/chart to a conventional image format. It will probably yield much better results than this conversion.
On the other hand, if a ps/eps is all you have, this might be useful.
Related Posts:
March 15th, 2008 at 8:45 am (8493) [Quote]
Hi,
Posted usingI am using Ubuntu Linux I am creating ps files but I need in jpeg format
I used the below conversion to convert ps to jpeg, but I created only one
image but the ps files has 12 figures.
Could you please suggest me how to solve this problem
” gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=myfile.jpg myfile.eps”
Thanking you
D Srinivas
March 15th, 2008 at 5:54 pm (8498) [Quote]
Are the figures on separate pages? Then you can split the original ps file with:
This will produce bunch of files named myfile001.ps, myfile002.ps, myfile003.ps and etc - one file per page.
Take these files and run them through the stuff above and you should be good.
Let me know if that helps.
If this doesn’t work (some ps files just don’t cooperate with this method_ I’d just recommend to open the ps file, and take a screenshot of each chart with something like Ksnapshot which lets you capture just a selected region of the screen.
Posted usingMarch 17th, 2008 at 5:31 am (8520) [Quote]
Dear Sir,
I used “gs -r300 -sDEVICE=pswrite -sOutputFile=ds%03d.ps -dNOPAUSE test.ps -c quit” to convert ps file which contains many images in that and
it created all individual figures
Now I am trying to convert back these ps files to jpg format
But I am unable to do it
I am using presently
“gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=jds%03d.jpg ds%03d.ps”
It is not converting to jpg format
Posted usingCould you please suggest me how to do it
Thanking you sir
D Srinivas
March 17th, 2008 at 10:30 am (8522) [Quote]
I don’t think it’s recognizing the “ds%03d.ps” as an input file name. I don’t think you can use the %03d notation this way. Have you tried running the command individually on each ps file?
Alsternatively, you can try this:
This will loop through all the .ps files in the current directory and create a jpeg for each of them.
Posted usingMarch 17th, 2008 at 12:21 pm (8525) [Quote]
Dear Sir
Posted usingI am thankful for your reply, which helped me very much
I tried on individual file, it worked well,
Now I success with this command
Thanking you sir
D Srinivas
March 17th, 2008 at 12:25 pm (8526) [Quote]
Glad I could help.
Posted usingMarch 17th, 2008 at 12:52 pm (8527) [Quote]
Dear Sir
Posted usingI am working with those commands fine, Now what the images created
are having very large file size
Could you please suggest me to reduce the file size of jpeg images
Because I am creating at a time 12 images giving a total size of
nearly 20 MB
So, Please could you please suggest me to reduce the file size
Thanking you sir
D Srinivas
March 17th, 2008 at 2:05 pm (8529) [Quote]
Did you do the mogrify step from above? Set the resolution to something smaller (like 320×320 for example) and see if that drops down the size.
I’d try -sample instead of -resize option - this way it will resample the image hopefully resulting in much greater size reduction.
Posted usingMarch 17th, 2008 at 2:15 pm (8530) [Quote]
Dear Sir
Posted usingI am thankful to your reply
But In my computer I donot have mogrify command
Please kindly suggest me
Thanking you sir
D Srinivas
March 17th, 2008 at 2:18 pm (8531) [Quote]
It’s part of the Image Magic package. You’re on Ubuntu, right?
That should install mogrify and bunch of other useful image manipulation tools.
Posted using