<?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>Milburn &#187; php</title>
	<atom:link href="http://instantsolve.net/blog/category/webdesign/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://instantsolve.net/blog</link>
	<description>The Life and Work of Thomas Milburn</description>
	<lastBuildDate>Wed, 14 Oct 2009 10:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ExcelOff</title>
		<link>http://instantsolve.net/blog/2009/04/exceloff/</link>
		<comments>http://instantsolve.net/blog/2009/04/exceloff/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 19:51:10 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=176</guid>
		<description><![CDATA[Let me introduce my latest tool: ExcelOff. It cleans up badly formed tables created by Microsoft Excel and similarly bad programs. This tool came about because I have created a site which users can edit and add tables to through a visual editor. Unfortunately copying and pasting from Excel into this visual editor results in [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><span title="L" class="cap"><span>L</span></span>et me introduce my latest tool: <a href="http://instantsolve.net/exceloff/">ExcelOff</a>. It cleans up badly formed tables created by Microsoft Excel and similarly bad programs.</p>
<p>This tool came about because I have created a site which users can edit and add tables to through a visual editor. Unfortunately copying and pasting from Excel into this visual editor results in &#8220;tag soup&#8221;!<span id="more-176"></span> I needed a solution.</p>
<p>I looked around and found <a href="http://wordoff.org/">WordOff</a> which cleans up word documents but doesn&#8217;t work on tables. I decided to take the code, convert it to PHP and modify it so that it doesn&#8217;t get ris of some of the essential stuff for tables. With the help of David Hopkin&#8217;s  <a href="http://semlabs.co.uk/journal/php-strip-attributes-class-for-xml-and-html">Strip Attributes Class</a></p>
<p>Please go to <a href="http://instantsolve.net/exceloff/">ExcelOff</a>, copy and paste a table from Excel or similar. Click clean up and lines of beautifully formed HTMl code will result!</p>
<p>Hopefully I will be able to incorporate this into a WordPress plugin for all WordPress users to conveniently use. Watch this space.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/04/exceloff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Quiz</title>
		<link>http://instantsolve.net/blog/2009/03/php-quiz/</link>
		<comments>http://instantsolve.net/blog/2009/03/php-quiz/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 17:16:45 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=135</guid>
		<description><![CDATA[Do you know your PHP? If you think you do please try out the PHP quiz. This is part of a web application which I am developing. It is currently in the beta state so I would appreciate any feedback.]]></description>
			<content:encoded><![CDATA[<p class="first-child "><img class="alignright size-full wp-image-137" title="PHP quiz" src="http://instantsolve.net/blog/wp-content/uploads/2009/03/image1.gif" alt="PHP quiz" width="200" height="200" /> <span title="D" class="cap"><span>D</span></span>o you know your PHP? If you think you do please try out the <a href="http://instantsolve.net/quiz/view/php/">PHP quiz</a>. This is part of a web application which I am developing. It is currently in the beta state so I would appreciate any feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/03/php-quiz/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exploring Fractals</title>
		<link>http://instantsolve.net/blog/2009/02/exploring-fractals/</link>
		<comments>http://instantsolve.net/blog/2009/02/exploring-fractals/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 12:49:34 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=105</guid>
		<description><![CDATA[Fractals are some of the most intriguing shapes. The Mandelbrot set is one of the most intriguing fractal sets. To be honest with you I don&#8217;t really get what it represents and why it has such a weird shape but I know that it is intriguing to see. For those mathematical boffins the Mandelbrot set [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><img src="http://instantsolve.net/blog/wp-content/uploads/2009/02/mandelbrot3.gif" alt="" title="mandelbrot3" width="200" height="200" class="alignleft size-medium wp-image-125" /><span title="F" class="cap"><span>F</span></span>ractals are some of the most intriguing shapes. The Mandelbrot set is one of the most intriguing fractal sets. To be honest with you I don&#8217;t really get what it represents and why it has such a weird shape but I know that it is intriguing to see.</p>
<p>For those mathematical boffins the <a href="http://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot set</a> can be defined as the set of complex values of c for which the orbit of 0 under iteration of the complex quadratic polynomial z<sub>n+1</sub> = z<sub>n</sub><sup>2</sup> + c remains bounded. That is, a complex number, c, is in the Mandelbrot set if, when starting with z<sub>0</sub>=0 and applying the iteration repeatedly, the absolute value of z<sub>n</sub> never exceeds a certain number (that number depends on c) however large n gets. <span id="more-105"></span></p>
<p>I decided to create a PHP script which could visualise the Mandelbrot set for me. With a bit of research, I found some basic code which I modified to make the script. You are free to use and distribute it as you wish. The script does work but It is isn&#8217;t perfect so use at your own risk.</p>
<p><code>&lt;?php<br />
class Mandelbrot<br />
{<br />
var $im;<br />
function colour($value){<br />
$value=$value*ceil(1200/$this-&gt;its);<br />
if($value&lt;256){<br />
$r=255;<br />
$g=$value;<br />
$b=0;<br />
}elseif($value&lt;512){<br />
$r=511-$value;<br />
$g=255;<br />
$b=0;<br />
}elseif($value&lt;768){<br />
$r=0;<br />
$g=255;<br />
$b=$value-512;<br />
}elseif($value&lt;1024){<br />
$r=0;<br />
$g=1023-$value;<br />
$b=255;<br />
}elseif($value&lt;1280){<br />
$r=$value-1024;<br />
$g=0;<br />
$b=255;<br />
}elseif($value&lt;1536){<br />
$r=255;<br />
$g=0;<br />
$b=1535-$value;<br />
}<br />
return imagecolorallocate($this-&gt;im, $r, $g, $b);<br />
}<br />
function Mandelbrot()<br />
{<br />
$this-&gt;im = @imagecreatetruecolor(200, 200);<br />
$this-&gt;y1=is_numeric($_GET['y'])?$_GET['y']:0;<br />
$this-&gt;x1=is_numeric($_GET['x'])?$_GET['x']:0;<br />
$zoom=is_numeric($_GET['zoom'])?100*$_GET['zoom']:100;<br />
$this-&gt;its=(is_numeric($_GET['its']) and $_GET['its']&lt;=1200 and $_GET['its']&gt;0)?$_GET['its']:100;<br />
$d1 = microtime(1);<br />
for ($y = -100; $y &lt; 100; $y++) {<br />
for ($x = -100; $x &lt; 100; $x++) {<br />
$val=$this-&gt;iterate($y/$zoom,$x/$zoom);<br />
imagesetpixel($this-&gt;im, $x+100, $y+100, $this-&gt;colour($val));<br />
}<br />
}<br />
$d2 = microtime(1);<br />
$diff = $d2 - $d1;<br />
header("Elapsed: $diff");<br />
header('Content-Type: image/png');<br />
imagepng($this-&gt;im);<br />
}<br />
function iterate($x,$y)<br />
{<br />
$cr = $y+$this-&gt;y1;<br />
$ci = $x+$this-&gt;x1;<br />
$zi = 0.0;<br />
$zr = 0.0;<br />
$i = 0;<br />
while ($i &lt; $this-&gt;its and $zi2 + $zr2 &lt; 4) {<br />
$i++;<br />
$temp = $zr * $zi;<br />
$zr2 = $zr * $zr;<br />
$zi2 = $zi * $zi;<br />
$zr = $zr2 - $zi2 + $cr;<br />
$zi = $temp + $temp + $ci;<br />
}<br />
return $i;<br />
}<br />
}<br />
$m = new Mandelbrot();<br />
?&gt;</code></p>
<p><img src="http://instantsolve.net/blog/wp-content/uploads/2009/02/451px-hsv-rgb-comparisonsvg-300x220.png" alt="" title="451px-hsv-rgb-comparisonsvg" width="300" height="220" class="alignleft size-medium wp-image-106" /></p>
<p>The script works in a simple way. It creates a blank canvas of 200&#215;200 pixels. For each pixel it uses the escape time algorithm to check if a point is within the set or not. A value is then returned for how long it took a point to reach the escape condition. Some points take millions of cycles to reach the escape condition so we set a maximum iteration limit. This defines how much detail we see in the mandelbrot set.</p>
<p>This value is used to define the colour of the point. Instead of using value to define the brightness of the point I use the value to define the hue of the point as there are many more possible hues than possible greyscale values. To convert a value into an RGB value needed to plot the point I use a special algorithm. The image above roughly shows how the RGB values are worked out.</p>
<p><img src="http://instantsolve.net/blog/wp-content/uploads/2009/02/mandelbrot.gif" alt="" title="mandelbrot" width="200" height="200" class="alignleft size-medium wp-image-108" /></p>
<p>I have made the script take 4 input parameters, the x and y coordinates the amount of zoom and the maximum number of iterations allowed. By messing around with these paarmeters you can explore the mandelbrot set in stunning detail.</p>
<p>The outputted images are simply amazing. The image to the left is found at a magnification of 200,000. Its a miniature replica of the Mandelbrot set.</p>
<p><img src="http://instantsolve.net/blog/wp-content/uploads/2009/02/mandelbrot2.gif" alt="" title="mandelbrot2" width="200" height="200" class="alignright clear size-medium wp-image-111" /></p>
<p>To show you just how much magnification you can get watch the following animation. It goes from a magnification of 1 to 1 billion. With a little more processing time you could easily go much deeper to many billions of billions of times magnification! </p>
<p>I would put the Mandelbrot explorer script online however it is very computationally intense. It takes around 5 seconds to generate 1 image.</p>
<p><strong>Important Update: You can now <a href="http://instantsolve.net/mandelbrot.htm">explorer the mandelbrot set</a>!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/02/exploring-fractals/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Anaglyphs Types</title>
		<link>http://instantsolve.net/blog/2009/01/anaglyphs-types/</link>
		<comments>http://instantsolve.net/blog/2009/01/anaglyphs-types/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 11:45:07 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=101</guid>
		<description><![CDATA[Having recently added the anaglyph creator to my main website I decided to add some more options. Up till now I have offered bog standard colour anaglyphs. There are in fact several different ways of generating anaglyphs to get an optimal 3D image. For a full comparison see this article. The different types of anaglyphs [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><span title="H" class="cap"><span>H</span></span>aving recently added the <a href="http://instantsolve.net/anaglyph/">anaglyph creator</a> to my main website I decided to add some more options. Up till now I have offered bog standard colour anaglyphs. There are in fact several different ways of generating anaglyphs to get an optimal 3D image. For a full comparison see <a href="http://www.3dtv.at/Knowhow/AnaglyphComparison_en.aspx">this article</a>. The different types of anaglyphs are:</p>
<p><strong>True:</strong> This but only displays the red and blue channels and doesn&#8217;t preserve any colour. The advantages are no ghosting but it does result in a dark image.</p>
<p><strong>Greyscale:</strong> This creates a lighter image than the true anaglyph but results in more ghosting. Again no colour is preserved.</p>
<p><strong>Colour:</strong> This preserves most of the colour but causes retinal rivalry. This is the type of anaglyph which I originally offered.</p>
<p><strong>Half Colour:</strong> This preserves less of the colour but reduces the retinal rivalry.</p>
<p><strong>Optimised:</strong> This uses none of the red channel from the original image so preserves none of the red colours but most of the blue and green. The advantages are almost no retinal rivalry.</p>
<p>I now believe that my <a href="http://instantsolve.net/anaglyph/">anaglyph creator</a> is the most comprehensive anaglyph creator available on the web. Please try it out with your own images and compare the different anaglyph types.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/01/anaglyphs-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instant Solve Updates</title>
		<link>http://instantsolve.net/blog/2009/01/instant-solve-updates/</link>
		<comments>http://instantsolve.net/blog/2009/01/instant-solve-updates/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 17:54:24 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=97</guid>
		<description><![CDATA[It&#8217;s the new year and I haven&#8217;t posted on my blog or made any modifications to my website for a long time. I&#8217;ve got around to making a few changes to my main site Instant Solve. I&#8217;ve updated Instant Solve with two new tools. The first is the anaglyph creator which I created a while [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><span title="I" class="cap"><span>I</span></span>t&#8217;s the new year and I haven&#8217;t posted on my blog or made any modifications to my website for a long time. I&#8217;ve got around to making a few changes to my main site Instant Solve.</p>
<p>I&#8217;ve updated Instant Solve with two new tools. The first is the <a href="http://instantsolve.net/anaglyph/">anaglyph creator</a> which I created a <a href="http://instantsolve.net/blog/2008/06/the-anaglyph-creator/">while ago</a>. Please try it out. Some fabulous images have been made with the anaglyph creator.</p>
<p>The second is a <a href="http://instantsolve.net/translate/">translation tool</a>. It relies on the Google languages API. The translation tool is as good as Google translate but offers real time Ajax translation of text. Other features may also be added at a later date. If you do have any ideas or feedback, please leave a comment.</p>
<p>A few more tools are in the pipeline such as a maths tool which can help with solving equations, trigonometry, integration and differentiation. Unfortunately, this tool is proving more difficult than I first thought. Other projects are a kakuro and a griddler solver however since both problems are NP complete the solutions take a large amount of computing power. I have also yet to come up with a meaningful interface which doesn&#8217;t heavily rely on javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/01/instant-solve-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instant Quiz beta release</title>
		<link>http://instantsolve.net/blog/2008/11/instant-quiz-beta-release/</link>
		<comments>http://instantsolve.net/blog/2008/11/instant-quiz-beta-release/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 13:05:24 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=80</guid>
		<description><![CDATA[I have been working on this project for a few months so I am very happy to announce that Instant Quiz is live. Instant Quiz is an application which creates quizzes for you to share with friends, colleagues or students. Please sign up and try out the application. I would much appreciate any feedback or [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><img src="http://instantsolve.net/blog/wp-content/uploads/2008/11/screenshot-300x161.gif" alt="" title="screenshot" width="300" height="161" class="alignleft size-medium wp-image-82" /><span title="I" class="cap"><span>I</span></span> have been working on this project for a few months so I am very happy to announce that <strong><a href="http://instantsolve.net/quiz/" title="Instant Quiz">Instant Quiz</a></strong> is live. Instant Quiz is an application which creates quizzes for you to share with friends, colleagues or students. Please <a href="http://instantsolve.net/quiz/signup/"title="Instant Quiz sign up">sign up</a> and try out the application. I would much appreciate any feedback or criticism to help improve the site.</p>
<p>Instant Quiz is still work in progress so some features haven&#8217;t been implemented yet. Quizzes don&#8217;t show answers and the quiz UI may change. In the next few weeks I am going to try and hook Instant Quiz up with Facebook so Facebook users can create quizzes for their friends to take.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2008/11/instant-quiz-beta-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtual Host with XAMPP</title>
		<link>http://instantsolve.net/blog/2008/06/virtual-host-with-xampp/</link>
		<comments>http://instantsolve.net/blog/2008/06/virtual-host-with-xampp/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 06:34:21 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=43</guid>
		<description><![CDATA[I like to develop my own PHP scripts and small applications. Up to now I&#8217;ve been uploading them to my online server. Of course that is bad practise because a small bug may open up a large security hole. My test scripts are reducing the security of things like my blog. So I&#8217;ve decided to [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><span title="I" class="cap"><span>I</span></span> like to develop my own PHP scripts and small applications. Up to now I&#8217;ve been uploading them to my online server. Of course that is bad practise because a small bug may open up a large security hole. My test scripts are reducing the security of things like my blog. So I&#8217;ve decided to use <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> to develop my scripts on my home computer before deploying them to the web.</p>
<p>If you&#8217;ve not heard of XAMPP it stands for</p>
<ul>
<li><strong>X</strong> (meaning cross-platform)</li>
<li><strong>A</strong>pache</li>
<li><strong>M</strong>ySQL</li>
<li><strong>P</strong>HP</li>
<li><strong>P</strong>erl</li>
</ul>
<p><span id="more-43"></span>It is a portable application which will work on a Mac PC or Linux. It comes bundled with pretty much everything you need to dive straight in. About a year ago I installed my own Apache, PHP and MySQL stack however it took me ages to install correctly, the MySQL stopped working and the installation was  a pain to start and stop. On the contrary XAMPP is a breeze to install and comes with a control panel.</p>
<p>There are a few pitfalls to developing code for an online site on a home computer. Firstly the functions available to you online will vary from those on your home computer because the software works slightly differently on different operating systems. The other pitfall is to develop some code and then have to rename all the links when you deploy it.</p>
<p>This is where building a virtual host comes in. Say I want to make a cheese identifying application (I don&#8217;t) and I have purchased the domain name whatcheese.com. When developing my code on XAMPP I can set up a virtual host which means that when I go to whatcheese.com I am redirected to my localhost.</p>
<p>In XAMPP with Windows this is a matter of changing two files. They may not be exactly the same files though on other operating systems. Firstly go to your xampp installation and go to Apache &gt; Conf &gt; Extra and open up httpd-vhosts.conf. In this file we can reference all the virtual hosts we want to create. Add the following to the file.</p>
<p><code>NameVirtualHost *:80<br />
&lt;virtualhost *:80&gt;<br />
ServerAdmin sampe@mysample.com<br />
DocumentRoot "C:/Program Files/xampp/htdocs" #existing document root<br />
ServerName localhost #if you type localhost in your browser you will get this virtual host<br />
&lt;/virtualhost&gt;<br />
&lt;virtualhost *:80&gt;<br />
ServerAdmin webmaster@mywordprees.com<br />
DocumentRoot "C:/whatcheese" #your new document root<br />
ServerName www.whatcheese.com #your virtual domain name<br />
ServerAlias whatcheese.com #your virtual domain name alias<br />
&lt;directory "C:/whatcheese"&gt; #your new document root again<br />
AllowOverride FileInfo AuthConfig Limit Indexes #set folder options<br />
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec<br />
&lt;limit GET POST OPTIONS&gt;<br />
Order allow,deny<br />
Allow from all<br />
&lt;/limit&gt;<br />
&lt;limitexcept GET POST OPTIONS&gt;<br />
Order deny,allow<br />
Deny from all<br />
&lt;/limitexcept&gt;<br />
&lt;/directory&gt;<br />
&lt;/virtualhost&gt;</code></p>
<p>This basically sets up a new virtual host in apache. If you go to whatcheese.com now you will be directed to the real online site whatcheese.com and if this doesn&#8217;t exist you will get an error like &#8220;server not found&#8221;. We need to tell our operating system to redirect to 127.0.0.1 (our computers local IP address).</p>
<p>On Windows you need to go to C:\WINDOWS\system32\drivers\etc\hosts Open up the file with a text editor and add the following lines to the bottom of the file:<br />
<code>127.0.0.1       www.whatcheese.com<br />
127.0.0.1       whatcheese.com</code><br />
This tells your browsers to go to 127.0.0.1 when they meet the domain name whatcheese.com as opposed to consulting a DNS server for the IP address.</p>
<p>That&#8217;s all there is too it. Restart apache and go to whatcheese.com and you will see whatever files you put in the C:/whatcheese directory. How cool! Now when you have finished developing your code on your home computer you can deploy it to your server without any problems. Just remember to remove the lines you wrote in the hosts file so you get sent to the online site.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2008/06/virtual-host-with-xampp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Anaglyph Creator</title>
		<link>http://instantsolve.net/blog/2008/06/the-anaglyph-creator/</link>
		<comments>http://instantsolve.net/blog/2008/06/the-anaglyph-creator/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 20:52:40 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=36</guid>
		<description><![CDATA[Having detailed how to create a script using the GD image library to create anaglyphs, I decided to create a webpage for those people not lucky enough to have their own web hosting. The page is very simple and it works similarly to the previous script. Any online tool is vulnerable to abuse but their [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><img class="alignleft size-thumbnail wp-image-34" title="imagephp" src="http://instantsolve.net/blog/wp-content/uploads/2008/06/imagephp-150x150.jpg" alt="" width="150" height="150" /></p>
<p><span title="H" class="cap"><span>H</span></span>aving detailed how to create a script using the GD image library to create anaglyphs, I decided to create a webpage for those people not lucky enough to have their own web hosting. The page is very simple and it works similarly to the previous script.</p>
<p>Any online tool is vulnerable to abuse but their are a number of precautions I needed to take. Firstly I needed to make the script secure. I don&#8217;t want people hacking my site through a little script I wrote just because I couldn&#8217;t be bothered to make it secure. On the contrary to what most people think, making file uploads safe isn&#8217;t too difficult. Firstly I make sure tat the user has uploaded to files and no upload errors occurred using the following if statement.</p>
<p><span id="more-36"></span><code>if(!empty($_FILES['left']) &amp;&amp; !empty($_FILES['right']) &amp;&amp; $_FILES['right']['error'] == 0 &amp;&amp; $_FILES['left']['error'] == 0) {</code></p>
<p>Secondly since only images can be uploaded I check they are really images using the getimagesize function. Some people use the files mime type to check whether the file is valid however this is insecure as the user can fake this. Looking at the file extension is a much better option because the Apache web server serves pages based on file extensions. Of course for extra-security checking both is advised to prevent users uploading malicious scripts.</p>
<p>The uploaded files are generally safe until you move them from the temp location to a directory where they can be served over the internet. As the getimagesize is more reliable than either of the other methods I have omitted them but only because I wasn&#8217;t going to move the uploaded files to a public area of the server.</p>
<p>There are several ways to fool getimagesize such as hiding PHP in a carefully created but still valid image file and giving the file a .php extension. I should also mention that all file upload names should be changed to prevent XSS attacks. As I mentioned earlier the reason why this amount of security suffices is because only the final image is placed on the public area.</p>
<p><code>$left_size = @getimagesize($_FILES['left']['tmp_name']);<br />
$right_size = @getimagesize($_FILES['right']['tmp_name']);<br />
if($left_size &amp;&amp; $right_size &amp;&amp; $left_size[0]==$right_size[0] &amp;&amp; $right_size[0]&lt;1025 &amp;&amp; $left_size[1]==$right_size[1] &amp;&amp; $right_size[1]&lt;1025 &amp;&amp; $left_size[2]==$right_size[2])</code></p>
<p>As you can see I have checked that the two images uploaded are the same size by checking that the height and width are equal and both less than 1025px. The images must be less than 1025px because larger files put too much of a strain on my server and can take over 5 seconds of processing time ouch!! There are other methods I could implement to stop people abusing this service such as allowing them to create only one anaglyph per session.</p>
<p><code>if(image($left_size)){<br />
$n=rand(1,1000);<br />
echo '&lt;img src="temp.jpg?'.$n.'" alt="Anaglyph"&gt;';<br />
}</code></p>
<p>In this section of code I pass the size of the image to the image function which creates an image and outputs the completed anaglyph as temp.jpg. You may be wondering why I append a random number to the image source. It&#8217;s actually to prevent the images being cached incorrectly. The subject of caching is in itself very complex so I ill leave this till another day to explain.</p>
<p>Finally the image function itself.</p>
<p><code>function image($size){<br />
//loads the files from the temp location<br />
$left = $_FILES['left']['tmp_name'];<br />
$right = $_FILES['right']['tmp_name'];<br />
//finds the type of image<br />
switch($size[2]) {<br />
case IMAGETYPE_GIF:<br />
$src_right = imagecreatefromgif($right);<br />
$src_left = imagecreatefromgif($left);<br />
break;<br />
case IMAGETYPE_JPEG:<br />
$src_right = imagecreatefromjpeg($right);<br />
$src_left = imagecreatefromjpeg($left);<br />
break;<br />
case IMAGETYPE_PNG:<br />
$src_right = imagecreatefrompng($right);<br />
$src_left = imagecreatefrompng($left);<br />
break;<br />
default:<br />
return false;<br />
}<br />
//finds the height and width of the image<br />
list($width, $height) = $size;<br />
//create the canvas<br />
$anaglyph= imagecreatetruecolor($width, $height);<br />
//for each pixel<br />
for ($y=0;$y&lt;$height;$y++){<br />
for ($x=0;$x&lt;$width;$x++){<br />
//find the colour<br />
$rgb_left = imagecolorat($src_left,$x,$y);<br />
//find the rgb value<br />
$cols = imagecolorsforindex($src_left, $rgb_left);<br />
$r = $cols['red'];<br />
$rgb_right = imagecolorat($src_right,$x,$y);<br />
$cols = imagecolorsforindex($src_right, $rgb_right);<br />
$g = $cols['green'];<br />
$b = $cols['blue'];<br />
//set the combined colour<br />
$color = imagecolorallocate($anaglyph,$r,$g,$b);<br />
//set the pixel on our canvas to the colour<br />
imagesetpixel($anaglyph,$x,$y,$color);<br />
}<br />
}<br />
//output the image as a jpeg to temp.jpg quality is 100 (best)<br />
imagejpeg($anaglyph,'temp.jpg',100);<br />
//don't forget to return true!<br />
return true;<br />
}</code></p>
<p>I&#8217;m happy for people to use this code to create their own anaglyph generators or for other projects but if you want to try this script out and create your own anglyphs go to <a href="http://instantsolve.net/anaglyph/">the anaglyph creator</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2008/06/the-anaglyph-creator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Anaglyphs with PHP</title>
		<link>http://instantsolve.net/blog/2008/06/creating-anaglyphs/</link>
		<comments>http://instantsolve.net/blog/2008/06/creating-anaglyphs/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 13:55:48 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=33</guid>
		<description><![CDATA[I created some stereographic pairs yesterday and used some online software to create an anaglyph for viewers with red and cyan glasses. Creating anaglyphs is in fact a really easy task. All that has to be done is to separate the red layer from the left image and the green and blue layers from the [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><span title="I" class="cap"><span>I</span></span> created some stereographic pairs yesterday and used some online software to create an anaglyph for viewers with red and cyan glasses. Creating anaglyphs is in fact a really easy task. All that has to be done is to separate the red layer from the left image and the green and blue layers from the right image. Finally the three layers are combined to create a colour anaglyph. Simple.</p>
<p>Having a little experience with PHP, I decided to create a simple script to create anaglyphs. First I needed to plan out how the script was going to work. The GD library has no native image filters except in PHP5. My plan works like so.</p>
<p><span id="more-33"></span>Find the size of the image<br />
For every x coordinate<br />
&nbsp;&nbsp;For every y coordinate<br />
&nbsp;&nbsp;&nbsp;&nbsp;Get the red value of the left pixel<br />
&nbsp;&nbsp;&nbsp;&nbsp;Get the green value of the right pixel<br />
&nbsp;&nbsp;&nbsp;&nbsp;Get the blue value of the right pixel<br />
&nbsp;&nbsp;&nbsp;&nbsp;Set the result pixel to red + green + blue<br />
Output image</p>
<p>In PHP this results in:</p>
<p><code><?php<br />
// The file for the left eye<br />
$left = 'left.jpg';<br />
// The file for the right eye<br />
$right = 'right.jpg';<br />
// Get the dimensions<br />
list($width, $height) = getimagesize($left);<br />
// Define our source images<br />
$src_right = imagecreatefromjpeg($right);<br />
$src_left = imagecreatefromjpeg($left);<br />
// Create the canvas<br />
$bwimage= imagecreatetruecolor($width, $height);<br />
//Reads the origonal colors pixel by pixel<br />
for ($y=0;$y<$height;$y++){<br />
	for ($x=0;$x<$width;$x++){<br />
		$rgb_left = imagecolorat($src_left,$x,$y);<br />
		$r = ($rgb_left >> 16) &#038; 0xFF;<br />
		$rgb_right = imagecolorat($src_right,$x,$y);<br />
		$g = ($rgb_right >> 8) &#038; 0xFF;<br />
		$b = $rgb_right &#038; 0xFF;<br />
		//This is where we create the color which is a mix of the red, green and blue channels<br />
		$color = imagecolorallocate($bwimage,$r,$g,$b);<br />
		imagesetpixel($bwimage,$x,$y,$color);<br />
	}<br />
}<br />
// This sets it to a .jpg, but you can change this to png or gif if that is what you are working with<br />
header('Content-type: image/jpeg');<br />
imagejpeg($bwimage);<br />
?></code></p>
<p>I didn&#8217;t think this would work at first because it seems too simple. My tests revealed the images I was outputing were the same as other programmes so it was working. Having said that since I cant find any red and cyan glasses I can&#8217;t really test it properly! Can anyone else verify the images below?</p>
<p><img src="http://instantsolve.net/blog/wp-content/uploads/2008/06/imagephp.jpg" alt="" title="imagephp" width="371" height="278" class="alignnone size-full wp-image-34" /></p>
<p><img src="http://instantsolve.net/blog/wp-content/uploads/2008/06/imagephp2.jpg" alt="" title="imagephp2" width="226" height="340" class="alignnone size-full wp-image-35" /></p>
<p><strong>Update: If you want to create your own anaglyphs why not use my <a href="http://instantsolve.net/anaglyph/" title="anaglyph creator">free anaglyph creator</a>.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2008/06/creating-anaglyphs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
