<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dammit Jim! &#187; command line</title>
	<atom:link href="http://scott.sherrillmix.com/blog/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Mon, 06 Feb 2012 05:19:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Converting .eps to .png Easily</title>
		<link>http://scott.sherrillmix.com/blog/programmer/converting-eps-to-png-easily/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/converting-eps-to-png-easily/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 00:11:35 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[black]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[eps]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[jpg]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=303</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <a href='http://www.imagemagick.org/'>ImageMagick</a> (available for all OSs I believe). ImageMagick lets you quickly convert (and <a href='http://www.imagemagick.org/Usage/'>create thumbnails, make B&#038;W,...</a>) from the command line without having to open up Photoshop.</p>
<p>For example, to convert an image named myPlot.eps to png you just need to enter <code>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 <code>-density</code> option (e.g. for 200 dpi <code>convert -density 200 myPlot.eps myPlot.png</code>). Make sure you put the <code>-density</code> part before the input image name.</p>
<p>Converting many files at once is where ImageMagick really shines. The <code>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 <code>mogrify -format png image*.eps</code>. In one shot, it will create image01.png, image02.png and image03.png.</p> 

<p>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 <code>convert</code> command to get around the problem like this:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-2">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span> f <span style="color: #b1b100;">in</span> `ls *.eps`; <span style="color: #b1b100;">do</span> </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;convert -density <span style="color: #cc66cc;color:#800000;">100</span> <span style="color: #0000ff;">$f</span> -flatten $<span style="color: #66cc66;">&#123;</span>f%.*<span style="color: #66cc66;">&#125;</span>.png;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">done</span> </div></li></ol></div>
</div></div><br />

<h4>Black Background Problem</h4>
<p>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 <a href='http://www.nabble.com/Background-issue-converting-.eps-to-.png-td20094851.html'>solution</a>, so I'll repost it here. Adding <code>-flatten</code> to the command (e.g. <code>convert myImage.eps -flatten myImage.png</code>) should change the background back to white. My <code>mogrify</code> command doesn't include the <code>-flatten</code> option so <code>convert</code> (like the example above) seems like the way to go.</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/converting-eps-to-png-easily/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

