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.
[tags]eps, ps, postscript, encapsulated postscript, jpg, jpeg, ghostscript, mogrify[/tags]
Hi,
I 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
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.
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
Could you please suggest me how to do it
Thanking you sir
D Srinivas
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.
Dear Sir
I 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
Glad I could help. :)
Dear Sir
I 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
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.
Dear Sir
I am thankful to your reply
But In my computer I donot have mogrify command
Please kindly suggest me
Thanking you sir
D Srinivas
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.
Thank you very much for the article. It really helped me out.
Hello Everyone,
I can’t able to create .jpg file while running the below php code in the oscommerce.
$ps2jpg=”gs -sOutputFile=” . DIR_FS_CATALOG . DIR_WS_GCIMAGES . gc_customer_directory($custno) . “/” . $code . “.ps -sDEVICE=jpeg -r300 -dNOPAUSE -dBATCH ” . DIR_FS_CATALOG . DIR_WS_GCIMAGES . gc_customer_directory($custno) . “/” . $code . “.jpg”;
Can any one please me regarding this issue.
Hi Luke,
Can you please help me for this problem…
iuse the following
convert filename.ps filename.jpeg
Hi
i want to convert a .eps,.tif,.psd file in jpeg format on window 7 using ghost script.
How to install ghost script on window 7?
is there different command for convert and resize in windows system? if yes then can you give me that one?
one more thing my directory contatin 20 eps file,so if you have command that convert all in once then please give me
Thanks
Dear Sir,
I have used mention below script to convert eps into jpg
gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=TvLDH-1bdmA.jpg TvLDH-1bdmA.eps
this command is not working and following error occured
ESP Ghostscript 8.15.3: Unrecoverable error, exit code 1
Kindly give me your kind suggestions.
Thank you