<?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>Ivan Villareal &#187; Xvfb and Firefox headless screenshot generator &#8211; Ivan Villareal</title>
	<atom:link href="http://ivanvillareal.com/tag/headless/feed/" rel="self" type="application/rss+xml" />
	<link>http://ivanvillareal.com</link>
	<description>IT stuff and more...</description>
	<lastBuildDate>Tue, 01 Nov 2011 23:00:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Xvfb and Firefox headless screenshot generator</title>
		<link>http://ivanvillareal.com/linux/xvfb-and-firefox-headles-screenshot-generator/</link>
		<comments>http://ivanvillareal.com/linux/xvfb-and-firefox-headles-screenshot-generator/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 00:25:41 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[headless]]></category>
		<category><![CDATA[virtual screen]]></category>
		<category><![CDATA[xvfb]]></category>

		<guid isPermaLink="false">http://ivanvillareal.com/?p=10</guid>
		<description><![CDATA[I&#8217;ve been working on a project that its main purpose is to get a screenshot of a bunch of different sites. The requirements for this project were simple. It has [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project that its main purpose is to get a screenshot of a bunch of different sites. The requirements for this project were simple.</p>
<ul>
<li>It has to be fast</li>
<li>It needs to run on linux</li>
</ul>
<p>I did some research, trying to found the best approach, I already knew Xvfb but haven&#8217;t worked with it in a real project, there wasn&#8217;t much info about what I was trying to do, however I&#8217;ve found some other automated solutions made in .NET that worked on windows using IE as rendering engine, but I&#8217;ve found nothing that worked out of the box in linux <img src='http://ivanvillareal.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I did found some interesting setups but nothing similar to what I was trying to achieve, and all the directions I&#8217;ve got, pointed me to the same place <strong>Xvfb</strong>, so because I&#8217;m a hands-on guy, I quickly cloned a minimal debian box to start playing with this.</p>
<p>First I&#8217;ve installed Xvfb, firefox and some fonts</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># apt-get install xvfb xfonts-base xfonts-75dpi xfonts-100dpi firefox</span></pre></div></div>

<p>After some package downloads I&#8217;ve got everything installed, I&#8217;ve checked the man page and found:</p>
<blockquote><p>-screen screennum WxHxD</p>
<p>This  option  creates  screen screennum and sets its width, height,</p>
<p>and depth to W, H, and D respectively.  By default, only  screen  0</p>
<p>exists and has the dimensions 1280x1024x12.</p></blockquote>
<p>So I did:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># Xvfb :1 -screen 0 1024x768x24 &amp;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">2665</span>
ivano ~ <span style="color: #666666; font-style: italic;"># Could not init font path element /usr/X11R6/lib/X11/fonts/misc, removing from list!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>cyrillic, removing from list<span style="color: #000000; font-weight: bold;">!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>Type1, removing from list<span style="color: #000000; font-weight: bold;">!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>X11R6<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>Type1, removing from list<span style="color: #000000; font-weight: bold;">!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>defoma<span style="color: #000000; font-weight: bold;">/</span>x-ttcidfont-conf.d<span style="color: #000000; font-weight: bold;">/</span>dirs<span style="color: #000000; font-weight: bold;">/</span>TrueType, removing from list<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>I&#8217;ve got some warnings from X, but nothing lethal, so now I have a Virtual X server ready to throw anything at it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># DISPLAY=:1 firefox http://google.com &amp;</span></pre></div></div>

<p>I have to set the DISPLAY variable to be the same as the virtual screen I&#8217;ve created, after this command firefox must be there so I need to get a screen shot of the virtual screen so I&#8217;ve used the image magick import tool</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># DISPLAY=:1 import -window root google.com.png</span></pre></div></div>

<p>When the import program ended I had a the following pg file:</p>
<div id="attachment_12" class="wp-caption aligncenter" style="width: 650px"><img class="size-full wp-image-12" title="google.com" src="http://ivanvillareal.com/wp-content/uploads/2009/09/google.com.jpg" alt="Firefox capture within Xvfb" width="640" height="480" /><p class="wp-caption-text">Firefox capture within Xvfb</p></div>
<p>This apparently worked well, however I did some more testing to found any possible problem and the only thing I&#8217;ve found was that firefox tried to restore the session because of the improper shutdown so I had to tweak the firefox profile to avoid this, apart from this there were no other significant issues.</p>
<p>I will talk more about how I implemented the backend and frontend for the entire solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://ivanvillareal.com/linux/xvfb-and-firefox-headles-screenshot-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

