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.

[tags]eps, ps, postscript, encapsulated postscript, jpg, jpeg, ghostscript, mogrify[/tags]

This entry was posted in programming and tagged , . Bookmark the permalink.


Related Posts:

  • Convert PNG to EPS
  • LaTex Reference
  • Convert JPG and PNG to EPS on Windows
  • Don’t Copy my Image!
  • Text Dumping PDF files
  • Poor Man’s Steganography
  • Latex: Rotate Inserted Images
  • Batch Upload Images to ImageShack using Perl
  • Download Website for Offline Reading with Wget
  • Creating Thumbnail Images with C#

  • 16 Responses to Convert PS and EPS images to JPEG

    1. Srinivas D INDIA Internet Explorer Windows says:

      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

      Reply  |  Quote
    2. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      Are the figures on separate pages? Then you can split the original ps file with:

      gs -r300 -sDEVICE=djet500 -sOutputFile=myfile.%03d.ps -dNOPAUSE myfile.ps -c quit

      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.

      Reply  |  Quote
    3. Srinivas INDIA Mozilla Firefox Windows says:

      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

      Reply  |  Quote
    4. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

      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:

      for f in $(ls *.ps); do
      gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=$f.jpg $f
      done

      This will loop through all the .ps files in the current directory and create a jpeg for each of them.

      Reply  |  Quote
    5. Srinivas INDIA Mozilla Firefox Windows says:

      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

      Reply  |  Quote
    6. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

      Glad I could help. :)

      Reply  |  Quote
    7. Srinivas INDIA Mozilla Firefox Windows says:

      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

      Reply  |  Quote
    8. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

      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.

      Reply  |  Quote
    9. Srinivas INDIA Mozilla Firefox Windows says:

      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

      Reply  |  Quote
    10. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

      It’s part of the Image Magic package. You’re on Ubuntu, right?

      sudo aptitude install imagemagic

      That should install mogrify and bunch of other useful image manipulation tools.

      Reply  |  Quote
    11. Astropiter CHILE Mozilla Firefox Ubuntu Linux says:

      Thank you very much for the article. It really helped me out.

      Reply  |  Quote
    12. Suresh INDIA Mozilla Firefox Windows says:

      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.

      Reply  |  Quote
    13. Suresh INDIA Mozilla Firefox Windows says:

      Hi Luke,

      Can you please help me for this problem…

      Reply  |  Quote
    14. Praveen SLOVENIA Google Chrome Linux says:

      iuse the following
      convert filename.ps filename.jpeg

      Reply  |  Quote
    15. Tatva168 INDIA Mozilla Firefox Windows says:

      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

      Reply  |  Quote
    16. Sana AUSTRALIA Mozilla Firefox SuSE Linux says:

      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

      Reply  |  Quote

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">