<?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>adamhopkinson.co.uk &#187; code</title>
	<atom:link href="http://adamhopkinson.co.uk/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://adamhopkinson.co.uk/blog</link>
	<description></description>
	<lastBuildDate>Thu, 26 Aug 2010 22:17:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-RC1</generator>
		<item>
		<title>Sharpen an image using PHP and GD</title>
		<link>http://adamhopkinson.co.uk/blog/2010/08/26/sharpen-an-image-using-php-and-gd/</link>
		<comments>http://adamhopkinson.co.uk/blog/2010/08/26/sharpen-an-image-using-php-and-gd/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 22:17:44 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sharpen]]></category>

		<guid isPermaLink="false">http://adamhopkinson.co.uk/blog/?p=153</guid>
		<description><![CDATA[PHP and GD can be used to sharpen images on the fly - read on to find out how.]]></description>
			<content:encoded><![CDATA[<p>PHP and GD can sharpen images by providing a matrix to <code>imageconvolution</code>:</p>
<pre>// create the image resource from a file
$i = imagecreatefromjpeg('otter.jpg');

// define the sharpen matrix
$sharpen = array(
	array(0.0, -1.0, 0.0),
	array(-1.0, 5.0, -1.0),
	array(0.0, -1.0, 0.0)
);

// calculate the sharpen divisor
$divisor = array_sum(array_map('array_sum', $sharpen));

// apply the matrix
imageconvolution($i, $sharpen, $divisor, 0);

// output the image
header('Content-Type: image/jpeg');
imagejpeg($i);</pre>
<div id="attachment_157" class="wp-caption aligncenter" style="width: 424px"><img class="size-full wp-image-157" title="Otter, before and after sharpening" src="http://adamhopkinson.co.uk/blog/wordpress/wp-content/uploads/2010/08/otter.jpg" alt="Otter, before and after sharpening" width="414" height="164" /><p class="wp-caption-text">Otter, before and after sharpening</p></div>
<p><a title="Image credit" href="http://www.flickr.com/photos/kevenlaw/" target="_blank">Image courtesy Kevin Law</a></p>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2010/08/26/sharpen-an-image-using-php-and-gd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZooPHP &#8211; a PHP wrapper for Zootool</title>
		<link>http://adamhopkinson.co.uk/blog/2010/04/12/zoophp-a-php-wrapper-for-zootool/</link>
		<comments>http://adamhopkinson.co.uk/blog/2010/04/12/zoophp-a-php-wrapper-for-zootool/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 22:31:15 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zootool]]></category>

		<guid isPermaLink="false">http://www.adamhopkinson.co.uk/blog/?p=132</guid>
		<description><![CDATA[Zootool is fast becoming the most practical and funkiest way to bookmark online. With the recent addition of an API, I've created a PHP wrapper to ease embedding of Zootool data.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a title="Zootool bookmarks" href="http://zootool.com">Zootool</a> more and more recently to bookmark things I see on the web. The visual representation of saved items works better for me than <a title="Delicious bookmarking" href="http://delicious.com">Delicious</a> and browser bookmarks are a non-starter these days.</p>
<p>Since the news of an API last week, I&#8217;ve been working on a little class wrapper &#8211; partly to hone my OOP skills and partly to support some great work by Bastian &#8211; and my class is now ready. I&#8217;ve named it ZooPHP.</p>
<pre>$zoo = new ZooPHP($key, $secret);
$zoo->getPopularItems();</pre>
<p><span id="more-132"></span></p>
<p>To start using ZooPHP, you&#8217;ll need a <a href="http://zootool.com/api/keys">Zootool API key</a>. The script is released under a BSD license and is documented, but should be fairly self-explanatory:</p>
<pre>$zoo-&gt;setAuth('username', 'password');
$zoo-&gt;setFormat('array');
$zoo-&gt;getUser('bastian');
$zoo-&gt;getUserFriends('bastian');
$zoo-&gt;getUserFollowers('bastian');
$zoo-&gt;getUserItems('bastian');
$zoo-&gt;getLatestItems();
$zoo-&gt;getItem('iw6og3');
$zoo-&gt;getPopularItems();
$zoo-&gt;addItem('adamhopkinson.co.uk', 'adamhopkinson.co.uk', 'zoophp, php, wrapper');</pre>
<p>You&#8217;ll only need to call <code>setAuth</code> if you want to <code>add</code> items or return private items with <code>getItems</code>.</p>
<p><a class="download" title="Download ZooPHP" href="/files/code/zoophp/zoophp.zip">Click here to download your copy of ZooPHP »</a></p>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2010/04/12/zoophp-a-php-wrapper-for-zootool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox Themes causing out of position pixels</title>
		<link>http://adamhopkinson.co.uk/blog/2009/08/14/firefox-themes-causing-out-of-position-pixels/</link>
		<comments>http://adamhopkinson.co.uk/blog/2009/08/14/firefox-themes-causing-out-of-position-pixels/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 11:22:54 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.adamhopkinson.co.uk/blog/?p=127</guid>
		<description><![CDATA[That Web Guy had a problem with a design not being pixel perfect &#8211; only it turned out to be down to the theme he was using in Firefox. Bug?]]></description>
			<content:encoded><![CDATA[<p><cite>That Web Guy</cite> had a problem with a design not being pixel perfect &#8211; only it turned out to be <a href="http://www.thatwebguyblog.com/show_article.php?id=2673">down to the theme he was using in Firefox</a>. Bug?</p>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2009/08/14/firefox-themes-causing-out-of-position-pixels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add an address lookup to your web forms &#8211; Part 1</title>
		<link>http://adamhopkinson.co.uk/blog/2007/05/13/add-an-address-lookup-to-your-web-forms-part-1/</link>
		<comments>http://adamhopkinson.co.uk/blog/2007/05/13/add-an-address-lookup-to-your-web-forms-part-1/#comments</comments>
		<pubDate>Sun, 13 May 2007 12:49:35 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.adamhopkinson.co.uk/blog/2007/05/13/add-an-address-lookups-to-your-web-forms-part-1/</guid>
		<description><![CDATA[In this tutorial I&#8217;m going to show you how to add an inline address lookup to your web forms using the PostcodeAnywhere webservice and the Yahoo! Connection Manager. Get a PCA account First, you&#8217;ll need to sign up to Postcode&#160;&#8230; <a href="http://adamhopkinson.co.uk/blog/2007/05/13/add-an-address-lookup-to-your-web-forms-part-1/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;m going to show you how to add an inline address lookup to your web forms using the <a href="http://www.postcodeanywhere.co.uk/" title="PostcodeAnywhere">PostcodeAnywhere</a> webservice and the Yahoo! <a href="http://developer.yahoo.com/yui/connection/" title="Yahoo Connection Manager">Connection Manager</a>.</p>
<p><span id="more-102"></span></p>
<h3>Get a PCA account</h3>
<p>First, you&#8217;ll need to sign up to Postcode Anywhere and add some credits. A beginner pack of 300 credits will set you back Â£25+VAT and will get you 300 address lookups (if you only want the basic details returned for each address).</p>
<h3>Use PHP to build the webservice client</h3>
<p>An AJAX lookup works by passing some data to a script on the webserver, which performs some translation (in our case, connects to the webservice) and returns the result to the page where javascript makes the updates. Create a new php file on your webserver call getpostcode.php</p>
<p>Set up the defaults for the lookup:</p>
<pre name="code" class="php:nogutter">
&lt;?php

$account_code = 'PCA_ACCOUNT';
$license_code = 'PCA_LICENCE';

$postcode = '';
$building = '';

?&gt;</pre>
<p>Then, get the postcode and building number or name from the query string:</p>
<pre name="code" class="php:nogutter">
if ( array_key_exists('postcode', $_QUERY) ) {
	$postcode = $_QUERY['postcode'];
}

if ( array_key_exists('building', $_QUERY) ) {
	$building = $_QUERY['building'];
}</pre>
<p>Then we have to build the REST url that will ask the webservice for the address:</p>
<pre name="code" class="php:nogutter">
$url = 'http://services.postcodeanywhere.co.uk/csv.aspx?';
$url .= 'account_code=' . $account_code;
$url .= '&amp;license_code=' . $license_code;
$url .= '&amp;action=fetch';
$url .= '&amp;postcode=' . $postcode;
$url .= '&amp;building=' . $building;
$url .= '&amp;style=simple';</pre>
<p>Use the php file function to get the data from the webservice into a variable called $data</p>
<pre name="code" class="php:nogutter">$data = file($url);</pre>
<p>We&#8217;ve asked the webservice to return the data in csv format, so we&#8217;re expecting two lines. The first will contain the field names and the second will contain the values. First, we want to return an error if the webservice call failed:</p>
<pre name="code" class="php:nogutter">
if(!$data) {
	die('{"status":"error"}');
}</pre>
<p>The status: error message is in JSON format so that it can be understood by the javascript which will handle the address lookup.</p>
<p>The php file function returns an array, with each line in a different array element &#8211; so the first line will be in $data[0] and the second in $data[1] (arrays always start at 0 not 1!).</p>
<p>Next we want to trim any whitespace such as spaces or newline characters from the end of each line:</p>
<pre name="code" class="php:nogutter">$data[0] = trim($data[0]);
$data[1] = trim($data[1]);</pre>
<p>then we trim all extra speech marks from the start and end to help us split the lines up</p>
<pre name="code" class="php:nogutter">$data[0] = trim($data[0], '"');
$data[1] = trim($data[1], '"');</pre>
<p>Now we can split the lines into two arrays, one for field names and one for values</p>
<pre name="code" class="php:nogutter">$field_names = explode('","', $data[0]);
$field_values = explode('","', $data[1]);</pre>
<p>and throw up an error if the number of fields isn&#8217;t the same as the number of values</p>
<pre name="code" class="php:nogutter">if(count($field_names) != count($field_values)) {
	die('{"status":"error"}');
}</pre>
<p>Empty the $data array and loop through the field names and values, building up an array of name =&gt; value pairs</p>
<pre name="code" class="php:nogutter">$data = array();

for($counter = 0; $counter &lt; count($field_names); $counter++) {
	$data[$field_names[$counter]] = $field_values[$counter];
}</pre>
<p>PostcodeAnywhere returns a field called error_number if there&#8217;s a problem in the request. If this field exists, return an error to the form:</p>
<pre name="code" class="php:nogutter">if(array_key_exists('error_number', $data)) {
	die('{"status":"error"}');
}</pre>
<p>Finally, output the data in JSON format:</p>
<pre name="code" class="php:nogutter">$output = '';
foreach($data AS $key=&gt;$value) {
	$output .= '"' . $key . '":"' . $value . '",';
}
//$output = trim($output, ',');
$output = '{"status":"ok",' . $output . '}';
echo $output;</pre>
<p>In part 2, we&#8217;ll look at how to use the Yahoo Connection Manager to put this data on your form. Check back in a few days&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2007/05/13/add-an-address-lookup-to-your-web-forms-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bite Size Standards is not a failure</title>
		<link>http://adamhopkinson.co.uk/blog/2006/07/13/bite-size-standards-is-not-a-failure/</link>
		<comments>http://adamhopkinson.co.uk/blog/2006/07/13/bite-size-standards-is-not-a-failure/#comments</comments>
		<pubDate>Thu, 13 Jul 2006 21:50:01 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.adamhopkinson.co.uk/2006/07/13/bite-size-standards-is-not-a-failure/</guid>
		<description><![CDATA[John Oxton (of joshuaink.com) writes that his recent project Bite Size Standards is &#8216;currently a failure&#8217;, as it has received some criticism of late. The site was set up six months ago to serve little tidbits of code and understanding,&#160;&#8230; <a href="http://adamhopkinson.co.uk/blog/2006/07/13/bite-size-standards-is-not-a-failure/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>John Oxton (of <a title="JoshuaInk" href="http://joshuaink.com/blog/755/bite-size-standards-is-currently-a-failure-but-thats-okay">joshuaink.com</a>) writes that his recent project <a title="Bite Size Standards" href="http://bitesizestandards.com/">Bite Size Standards</a> is &#8216;currently a failure&#8217;, as it has received some criticism of late. The site was set up six months ago to serve little tidbits of code and understanding, and is a purely altruistic effort from John and his helpers to help a few people out along the way.</p>
<p>I didn&#8217;t see any criticism along the way, and I think what is being offered is top notch. Maybe just because something hasn&#8217;t lived up to the expectations of one person doesn&#8217;t make it a failure? It&#8217;s better than most people have done&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2006/07/13/bite-size-standards-is-not-a-failure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pages+ v0.2</title>
		<link>http://adamhopkinson.co.uk/blog/2006/03/04/pages-v02/</link>
		<comments>http://adamhopkinson.co.uk/blog/2006/03/04/pages-v02/#comments</comments>
		<pubDate>Sat, 04 Mar 2006 00:53:59 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.adamhopkinson.co.uk/2006/03/04/pages-v02/</guid>
		<description><![CDATA[I&#8217;ve released Pages+ v0.2 and moved it to it&#8217;s own page! Updates include a sort toolbar and a few slight tweaks.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released Pages+ v0.2 and moved it to <a href="/blog/code/pagesplus/" title="Pages+">it&#8217;s own page</a>! Updates include a sort toolbar and a few slight tweaks.</p>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2006/03/04/pages-v02/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WordPress plugin: Pages+</title>
		<link>http://adamhopkinson.co.uk/blog/2006/01/24/pagesplus/</link>
		<comments>http://adamhopkinson.co.uk/blog/2006/01/24/pagesplus/#comments</comments>
		<pubDate>Tue, 24 Jan 2006 22:25:10 +0000</pubDate>
		<dc:creator>Adam Hopkinson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.adamhopkinson.co.uk/2006/01/24/pagesplus/</guid>
		<description><![CDATA[Pages+ is my first decent wordpress plugin, and will be of use to those with many pages within their wordpress site. It replaces the Manage Â» Pages admin page with a more simple way of navigating to a page.]]></description>
			<content:encoded><![CDATA[<p class="update">Update: I&#8217;ve moved pages+ to it&#8217;s own page &#8211; <a href="/blog/code/pagesplus/" title="Pages+">click here to continue</a></p>
<p>Pages+ is my first decent wordpress plugin, and will be of use to those with many pages within their wordpress site. It replaces the Manage Â» Pages admin page with a more simple way of navigating to a page.</p>
<p><img src="/images/pagesplus.png" alt="Pages+ in WordPress 2" title="Pages+ in WordPress 2" align="middle" /></p>
<p><span id="more-62"></span>I&#8217;ve used it in wordpress 1.5 and 2.0 with no problems. The site it was developed for is currently at 2,200 pages(!) and is using this plugin as the main way of navigating through page administration. If you find it useful (or hate it), I&#8217;d appreciate a comment back.</p>
<p><a href="/downloads/pagesplus.zip" title="Pages+">Download Pages+</a></p>
<p class="update">Update: I&#8217;ve added <a href="http://www.croila.net/" target="_blank" title="www.croila.net">Croila&#8217;s</a> suggestion of a child page counter. Now, each title is followed by the number of direct (first level) child pages under that page.</p>
<h3>Instructions</h3>
<ol>
<li>Upload the pagesplus.php file into your wp-content/plugins folder on your website</li>
<li>In your wordpress admin area, click Plugins and activate Pages+</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://adamhopkinson.co.uk/blog/2006/01/24/pagesplus/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
	</channel>
</rss>

