<?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>Not A n00b &#187; webpage</title>
	<atom:link href="http://notan00b.com/tag/webpage/feed/" rel="self" type="application/rss+xml" />
	<link>http://notan00b.com</link>
	<description>Tutorials, Scripts, and Rants</description>
	<lastBuildDate>Wed, 12 May 2010 08:08:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP to create website thumbnails</title>
		<link>http://notan00b.com/2009/09/php-to-create-website-thumbnails/</link>
		<comments>http://notan00b.com/2009/09/php-to-create-website-thumbnails/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 00:46:20 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[frontpage]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[internetexplorer]]></category>
		<category><![CDATA[internetexplorer.application]]></category>
		<category><![CDATA[nails]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[shot]]></category>
		<category><![CDATA[thumb]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=230</guid>
		<description><![CDATA[Want to know how to create a thumbnail/screen shot of a webpage using PHP?  Well check it out here]]></description>
			<content:encoded><![CDATA[<p>Bing.com has an awesome feature that is popping up more and more all over the internet.  Most websites charge for this, as they should.  It isn&#8217;t something that can be done on a normal hosting plan, but can only be done (this way) on a Windows server, where Internet Explorer is installed and you have access to.  There are several ways to do this on Linux servers, but I am going to cover the Windows version.</p>
<p>In order to create an image for a thumbnail, we need to take a screen shot of webpage.  PHP GD class allows us to take screen shots of different windows.  PHP also allows us to control different windows, like Internet Explorer using the COM class.  So basically what we need to do is have PHP open up a window in Internet Explorer, navigate to a website, and then take a picture of that window, then save it/display it.  The tutorial shown on php.net shows exactly how to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.libgd.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Still working? */</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Busy</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">com_message_pump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagegrabwindow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;iesnap.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So this is SUPPOSED to load libgd.org and take a snap shot and save it to &#8220;iesnap.png&#8221;, and it DOES work, but only if your server allows it to work.  If it doesn&#8217;t you just get a black/blank picture.  </p>
<p>Windows rarely lets one program access another program via the desktop and control it.  By default, Apache isn&#8217;t allowed to open Internet Explorer on windows, so we have to add an exception.  </p>
<ol>
<li>On Vista, click the start button, and in the search box type &#8220;Services&#8221;.  </li>
<li>At the very top, there should be a link under Programs called Services.  Click that link. </li>
<li>It will open up all running services, and you will see Apache running (mine is Apache 2.2, and is the first entry).</li>
<li>Right click on it and select &#8220;Properties&#8221;</li>
<li>Navigate to the &#8220;Log On&#8221; tab</li>
<li>Click the box for &#8220;Allow service to interact with the desktop&#8221;</li>
<li>Save it and close the properties</li>
<li>Right click on Apache again</li>
<li>This time, click restart, and Apache will be restarted with the new features</li>
</ol>
<p>Now run your script again!  Vista pops up a little box alerting the user that a program is interact with the desktop.  Just ignore it and it will disappear in a few seconds.  After the program is complete, go to your web folder and you will see iesnap.png is now an image of a webpage!</p>
<p>Time to make some tweaks!  You will notice that it grabs the ENTIRE screen, meaning the tool bars and everything.  We will need to make a few adjustments to get rid of those.  The first one I made was to make the browser show as a full screen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FullScreen</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>That last line will make it display in the fullscreen mode, which takes care of the tool bars at the top, but I still see the footer and the side bar that I want to get rid of.  In order to do this, we need to crop a little, but GD doesn&#8217;t have a simple cropping method.  What I did was copied part of this picture to a new picture and resized it.  Keep in mind, my display settings are going to be different, and will require you to look at your picture and test it out:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$w</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$h</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;www.notan00b.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1263</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$w</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">780</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$h</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FullScreen</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/* Still working?*/</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Busy</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">com_message_pump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagegrabwindow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;iesnap.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Copy</span>
<span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">780</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output and free from memory</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>There we have it.  Even with the GET variables so you can reuse this script for AJAX or any HTML document.  My images were 1280&#215;800.  To remove the bars I scaled it down to 1263&#215;780, and they were removed almost perfectly, but it will be different for everyone.</p>
<p>I would post an example of it, but I am only hosted&#8230; I don&#8217;t actually pay for a VPS or private server just for one little blog.  Sorry folks.  If it was up to me, and I needed this service, I would probably pay a company to do it for me for a simple little website.  If you have a VPS with enough memory, this may work for you.  Good luck, let me know if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/php-to-create-website-thumbnails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
