{"id":303,"date":"2009-01-13T20:11:35","date_gmt":"2009-01-14T00:11:35","guid":{"rendered":"http:\/\/scott.sherrillmix.com\/blog\/?p=303"},"modified":"2009-06-10T03:34:00","modified_gmt":"2009-06-10T07:34:00","slug":"converting-eps-to-png-easily","status":"publish","type":"post","link":"http:\/\/scott.sherrillmix.com\/blog\/programmer\/converting-eps-to-png-easily\/","title":{"rendered":"Converting .eps to .png Easily"},"content":{"rendered":"
I end up generating a lot of postscript plots in R and other programs. Unfortunately, a lot of not so technical people have trouble opening postscript files so I end up having to convert these images to other formats pretty often. A really handy program for converting eps files to png (or jpg although that’s not really an optimal format for plots) is ImageMagick<\/a> (available for all OSs I believe). ImageMagick lets you quickly convert (and create thumbnails, make B&W,…<\/a>) from the command line without having to open up Photoshop.<\/p>\r\n For example, to convert an image named myPlot.eps to png you just need to enter Converting many files at once is where ImageMagick really shines. The Unfortunately, recent version of Imagemagick seem to be treating eps to png conversions oddly (see below) so mogrify isn’t cutting it on my files. If you have similar trouble (and you’re on Unix or Mac or Cygwin), you can just use a bit of Bash combined with the As I mentioned above, I started having trouble converting from eps to png after upgrading to ImageMagick 6.4. The transparent\/white backgrounds in my eps files were being converted to black backgrounds and making the figures unreadable. I guess it must be some change in how transparency is handled but I’m not totally sure what changed. It took me a bit of googling before I found the solution<\/a>, so I’ll repost it here. Adding convert myPlot.eps myPlot.png<\/code> (convert is a program in the ImageMagick package) at the command prompt and you’ll get a png file in myPlot.png. If you want to adjust the resolution (the default resolution is 72 dpi) of the output image, you can add the
-density<\/code> option (e.g. for 200 dpi
convert -density 200 myPlot.eps myPlot.png<\/code>). Make sure you put the
-density<\/code> part before the input image name.<\/p>\r\n
mogrify<\/code> command is probably the quickest option. For example, to convert the files image01.eps, image02.eps and image03.eps to png, just use the command
mogrify -format png image*.eps<\/code>. In one shot, it will create image01.png, image02.png and image03.png.<\/p> \r\n\r\n
convert<\/code> command to get around the problem like this:<\/p>\r\n[bash]\r\nfor f in `ls *.eps`; do \r\n convert -density 100 $f -flatten ${f%.*}.png;\r\ndone\r\n[\/bash]\r\n\r\n
Black Background Problem<\/h4>\r\n
-flatten<\/code> to the command (e.g.
convert myImage.eps -flatten myImage.png<\/code>) should change the background back to white. My
mogrify<\/code> command doesn’t include the
-flatten<\/code> option so
convert<\/code> (like the example above) seems like the way to go.<\/p>","protected":false},"excerpt":{"rendered":"I end up generating a lot of postscript plots in R and other programs. Unfortunately, a lot of not so technical people have trouble opening postscript files so I end up having to convert these images to other formats pretty often. A really handy program for converting eps files to png (or jpg although that’s […]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[415,73,414,411,408,690,412,413,410,409,99],"_links":{"self":[{"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/posts\/303"}],"collection":[{"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/comments?post=303"}],"version-history":[{"count":17,"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":487,"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/posts\/303\/revisions\/487"}],"wp:attachment":[{"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/media?parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/categories?post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/scott.sherrillmix.com\/blog\/wp-json\/wp\/v2\/tags?post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}