<?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>html tutorials &#124; css tutorials &#124; php tutorials &#124; Nodstrum Blog &#187; Code</title>
	<atom:link href="http://www.nodstrum.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nodstrum.com</link>
	<description>A coders playground.</description>
	<lastBuildDate>Wed, 23 Feb 2011 13:52:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Shorthand PHP IF/ELSE Statements = much shorter code!</title>
		<link>http://www.nodstrum.com/2008/02/14/shorthand-php-ifelse-statements-much-shorter-code/</link>
		<comments>http://www.nodstrum.com/2008/02/14/shorthand-php-ifelse-statements-much-shorter-code/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 11:27:47 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2008/02/14/shorthand-php-ifelse-statements-much-shorter-code/</guid>
		<description><![CDATA[You may or may not have heard of shorthand if/else statements, but they do exist, and trust me they make things SO much more ordered in your code when used in the right way. This is the Shorthand version &#8211; below this, if you cannot work it out for yourself is a nice description. // [...]]]></description>
			<content:encoded><![CDATA[<p>You may or may not have heard of shorthand if/else statements, but they do exist, and trust me they make things SO much more ordered in your code when used in the right way.</p>
<p>This is the Shorthand version &#8211; below this, if you cannot work it out for yourself is a nice description.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Will print out 'i am male' if $myGender is 'male' and vice-versa.</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$myGender</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'male'</span> ? <span style="color: #0000ff;">'i am male'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'I am female'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Description of how this actually works</strong><br />
We all (i would hope) know the normal way of writing if/else statements (here is a recap just incase)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myVar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myVar</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'My Var is TRUE!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'My Var is FALSE'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That sort of statement is great for in the body of your code, but when want a dynamic selector within your HTML code, it gets very messy.</p>
<p>EG:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myGender</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'male'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Gender is MALE.</span>
    <span style="color: #000088;">$maleOpt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'selected'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$femaleOpt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Gender is FEMALE.</span>
    <span style="color: #000088;">$maleOpt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$femaleOpt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'selected'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;select name=&quot;gender&quot;&gt;&lt;
option value=&quot;female&quot; &lt;?= $femaleOpt; ?&gt;&gt;Female&lt;/option&gt;
&lt;option value=&quot;male&quot; &lt;?= $maleOpt; ?&gt;&gt;Male&lt;/option&gt;
&lt;/select&gt;</pre></div></div>

<p>Now &#8211; that is alot to write and will make your HTML form look a total mess, this is where the shorthand comes in.  It allows us to write the same thing inline</p>
<p>Look:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;select name=&quot;gender&quot;&gt; 
&lt;option value=&quot;female&quot; &lt;?= ($myGender == 'female' ? 'selected' : ''); ?&gt;&gt;Female&lt;/option&gt;
&lt;option value=&quot;male&quot; &lt;?= ($myGender == 'male' ? 'selected' : ''); ?&gt;&gt;Male&lt;/option&gt;
&lt;/select&gt;</pre></div></div>

<p>As you can see &#8211; there is a huge difference in the amount of code &#8211; and if WordPress formatted it nicely &#8211; it would look loads better!</p>
<p><strong>And the all important Explanation!</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// This will echo selected to the screen if $myGender is male.</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$myGender</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'male'</span> ? <span style="color: #0000ff;">' selected'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So &#8211; $myGender is the variable we are checking, in this case we are checking to see if $myGender == &#8216;male&#8217;</p>
<p>The questionmark (?) seperates the &#8216;answers&#8217;.</p>
<p>The first &#8216;answer&#8217; is what is set/displayed when the query is true, the second is if the query is false.</p>
<p>This is the equilivent to :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myGender</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'male'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'selected'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hope that helps some of you out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2008/02/14/shorthand-php-ifelse-statements-much-shorter-code/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Captcha &#8211; in 5 lines of php :)</title>
		<link>http://www.nodstrum.com/2007/09/23/captcha/</link>
		<comments>http://www.nodstrum.com/2007/09/23/captcha/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 08:08:18 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/09/23/captcha/</guid>
		<description><![CDATA[Yes you read it right&#8230;! 5 lines of code I know its hard to believe but this has to be one of the simplest implementation of Captcha, mainly because i can&#8217;t find any easier ones. So here goes, this is how it works: At the top of the page with the form you want to [...]]]></description>
			<content:encoded><![CDATA[<p>Yes you read it right&#8230;! <span style="font-weight: bold" class="Apple-style-span">5 lines of code <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-weight: bold" class="Apple-style-span"></span>I know its hard to believe but this has to be one of the simplest implementation of Captcha, mainly because i can&#8217;t find any easier ones.</p>
<p>So here goes, this is how it works:</p>
<p>At the top of the page with the form you want to Captcha protect add these 3 lines of code, this generates the Captcha and adds it all to a nice variable to print out later:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'captcha.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$captcha</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Captcha<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$captchaImage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$captcha</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then in your form where you want the Captcha, usually at the bottom, just above the submit button add this line, enclosed in php tags of course, this adds the captcha elements to the form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$captchaImage</span><span style="color: #339933;">;</span></pre></div></div>

<p>So that is the form part done, now we just need to verify what the user has put in. For this i am going to assume that you are verifying atleast one part of the users input, so we need to add this line into it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$captcha</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>verify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$captcha</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>captchaInputName<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This would probably fit into your current checking like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$someothervariable</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$captcha</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>verify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$captcha</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span> captchaInputName<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">...</span></pre></div></div>

<p>Of course we have to add these 2 lines at the top of this processing page aswell (these are not included in the &#8217;5&#8242; because they have already been added.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'captcha.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$captcha</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Captcha<span style="color: #339933;">;</span></pre></div></div>

<p>And thats it, the class handles everything else, well you have to put the files on your web-server, create a new directory to store the images and make it writeable, but thats a one-shot 10 second job!</p>
<p><strong>Now for a screenshot:</strong></p>
<p><strong><img src="http://res.nodstrum.com/captcha/screenshots/screenshot_1.png" /></strong></p>
<p>Now for demo and the code:</p>
<p><a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=28">Captcha DEMO </a></p>
<p><a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=29">Captcha Formatted Source </a></p>
<p><a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=27">Captcha ZIP </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/09/23/captcha/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>MySQL Calendar</title>
		<link>http://www.nodstrum.com/2007/06/27/mysql-calendar/</link>
		<comments>http://www.nodstrum.com/2007/06/27/mysql-calendar/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 10:57:10 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/06/27/mysql-calendar/</guid>
		<description><![CDATA[VERSION 1.1 RELEASED! Changes: Added (by popular demand) Event deletion! Ok&#8230; I have finally got this script working! I have not done it like a tutorial because it is just too big, so here are a load of screen shots, There is a link to a fully functional demo and zip at the bottom! A [...]]]></description>
			<content:encoded><![CDATA[<p><strong>VERSION 1.1 RELEASED!</strong></p>
<p><em>Changes: Added (by popular demand) <strong>Event deletion</strong>! </em><br />
Ok&#8230; I have finally got this script working!</p>
<p>I have not done it like a tutorial because it is just too big, so here are a load of screen shots, <strong>There is a link to a fully functional demo and zip at the bottom!</strong></p>
<p><strong>A little setup information:</strong></p>
<p>1. Copy the entire calendar into whatever directory you want.</p>
<p>2. Create your database and import the &#8216;databaseSQL.sql&#8217; file into it, this will create the default data for running it.</p>
<p>3. Alter the &#8216;databaseConnection.php&#8217; file to show your connection details.That should be it..</p>
<p>NOTE:By default the username and password are both &#8216;<span style="font-weight: bold;">admin</span>&#8216; (without the quotes), i suggest you change your password in the control panel.</p>
<p>If you have any problems i will be happy to help, just post your query as a comment to this page.</p>
<p><strong>Screen Shots</strong></p>
<p><strong>Default View</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/defaultCalendar.png.png" alt="" /></p>
<p><span id="more-35"></span></p>
<p><strong>View Events</strong><br />
<img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/viewEvents.png" alt="" /></p>
<p><strong>View Events 2</strong><br />
<img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/noEvents.png" alt="" /></p>
<p><strong>Login</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/login.png" alt="" /></p>
<p><strong>Control Panel</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/controlPanel.png" alt="" /></p>
<p><strong>Add Event</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/addEvent1.png" alt="" /></p>
<p><strong>Add Event 2</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/addEvent2.png" alt="" /></p>
<p><strong>Downloads</strong></p>
<p><a href="http://res.nodstrum.com/mysqlCalendar/">MySQL Calendar V1.1 DEMO</a></p>
<p><a href="http://www.2big2send.com/shared.php?token=e3066c5a7376f9d83bfe3f1ae76e22a5">MySQL Calendar v1.1 ZIP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/06/27/mysql-calendar/feed/</wfw:commentRss>
		<slash:comments>292</slash:comments>
		</item>
		<item>
		<title>AJAX/PHP &#8211; the beginners guide to loading external content</title>
		<link>http://www.nodstrum.com/2007/02/27/ajaxcontentload/</link>
		<comments>http://www.nodstrum.com/2007/02/27/ajaxcontentload/#comments</comments>
		<pubDate>Tue, 27 Feb 2007 12:08:54 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/02/27/ajaxcontentload/</guid>
		<description><![CDATA[I&#8217;m going to assume that we all know, or have atleast heard of Prototype and script.aculo.us the two combine to form one powerful javascript library enabling developers to become designers (well, kind of). &#8211; Example and code at the bottom &#8211; I have created a ZIP file to get you up and running right away: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to assume that we all know, or have atleast heard of <a href="http://prototype.conio.net" target="_blank">Prototype</a> and <a href="http://script.aculo.us" target="_blank">script.aculo.us</a> the two combine to form one powerful javascript library enabling developers to become designers (well, kind of).<br />
<strong>&#8211; Example and code at the bottom &#8211;</strong></p>
<p><strong>I have created a ZIP file to get you up and running right away: <a href="http://www.2big2send.com/shared.php?token=488b8b61350ef8bf1cdb75efd298de40">Download it now!</a></strong></p>
<p>I was showing a friend a few days ago something i made for a university module, Multimedia Applications Desgn (a mouthful i know). Basically we had to create a website promoting our group as a duo, thats all your getting about the project as its not really relevant and a tad embarrassing should anyone find the site!</p>
<p>There was a part of the site that my friend really liked and wanted to incorporate into his final year project&#8230; after sketching it out for him on paper i reconed that other people could benefit.<br />
This has probably been splashed everywhere, but i havent seen anything that incorporates all the same characteristics on <a href="http://digg.com" target="_blank">Digg</a>.</p>
<p>So here is a quick, hopefully easy to understand, tutorial of how its done.</p>
<p><strong>Abstract</strong><br />
We are trying to achieve loading content into a &#8216;div&#8217; element without refreshing the page, as well as showing a cool loading window inplace of the content as it is loading.</p>
<p><span id="more-11"></span></p>
<p><strong>Method</strong><br />
1 HTML page and 1 PHP page are required.<br />
You dont need to follow my method exactly as there are probably many many more out there, this is just my simple approach that seems to work.</p>
<p><strong>The HTML Page</strong><br />
This page will be the one we want the user to stay on with the &#8216;div&#8217; element in it for loading the content into.</p>
<p>Firstly we need to include the script.aculo.us javascript files.<br />
I just unzipped the script.aculo.us javascript files into my own folder called &#8216;js&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/lib/prototype.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/src/scriptaculous.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Next we need to create a few functions to make our life easier.<br />
The reason for this is it makes them reuseable and therfore we dont need to make our code look messy, im a little anal about code being correctly formatted and using the same chunks of code over and over again when they could simply be made into functions.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> startLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// First we want to show the loading window then hide the content are we are loading into.</span>
  Element.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaLoading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Element.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaInternal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> finishLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// First we want to show the content are, then toggle the loading window so it fades away.</span>
  Element.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaInternel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// This happens 1 second after the mainAreaInternal is shown incase the content is still loading.</span>
  setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Effect.toggle('mainAreaLoading');&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> loadContent<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// We make use of the Ajax.Updater function to load the external data from our file.</span>
  <span style="color: #006600; font-style: italic;">// Start the loading window first by calling the function we made previously.</span>
  startLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Request the content and update the 'div' area (i'll explain this in more detail later).</span>
  <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaInternal'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rpc.php'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span> postBody<span style="color: #339933;">:</span><span style="color: #3366CC;">'content='</span><span style="color: #339933;">+</span> id <span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Now finish the loading.</span>
  finishLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next we have to make our &#8216;RPC file&#8217; (probably the wrong phrase to use, but it works for me).</p>
<p>Whatever you &#8216;echo&#8217; out to from this script will be what appears on the screen, html tags et-all, although i have found that outputting certain types of Javascript, like entire functions does not seem to work.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">// We are posting our request, like the 'method=&quot;post&quot;' in a form, so we need to catch it.</span>
  <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// The content to show is determined by the $content integer we send through from the javascript.</span>
  <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'This is the content for the FIRST case statement!'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Congratulations, you have loaded the second bit of content!'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
      <span style="color: #666666; font-style: italic;">// This default case catches any $content value that does not have a case. I'm giving a nice error message so you can work out what went wrong.</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Whoops, there was a problem in the switch.You passed: &lt;em&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/em&gt; to the switch statement in rpc.php.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end Content Switch.</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Here is the CSS Stylesheet to make all this possible</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">  <span style="color: #6666ff;">.mainAreaInternal</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#cccccc</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #6666ff;">.mainAreaLoading</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Ok, now that the backend is all there, we need to do the difficult part (probably the easy bit for everyone else!), making the HTML page.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;span style=&quot;cursor: pointer;&quot; onclick=&quot;loadContent(1);&quot;&gt;Load Content 1&lt;/span&gt;
    &lt;span style=&quot;cursor: pointer;&quot; onclick=&quot;loadContent(2);&quot;&gt;Load Content 2&lt;/span&gt;
&nbsp;
&lt;!-- Navigation End --&gt;
&nbsp;
&nbsp;
 
&nbsp;
This is the content that will be visible at the very beginning.
&nbsp;
&lt;!-- End Main Area Internal --&gt;
&nbsp;
&nbsp;
&lt;span style=&quot;position: relative; top: 100px; left: 100px;&quot;&gt;
        Loading Please Wait...
      &lt;/span&gt;
&nbsp;
&lt;!-- End Main Area --&gt;</pre></div></div>

<p><strong>Now for the little explaination</strong><br />
Basically the loading &#8216;div&#8217; area is always there, it is just hidden from view, so when you call the &#8216;startLoading()&#8217; function it shows it, then hides it after the allotted time.<br />
Adding new &#8216;cases&#8217; to the rpc.php file will allow more content to be loaded <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Example and Code</strong><br />
<a href="http://res.nodstrum.com/ajaxPHPContent/">Content Loading Example</a><br />
<a href="http://res.nodstrum.com/ajaxPHPContent/rpc.phps">RPC.php Source Code</a></p>
<p><a title="Get the Full Code in a ZIP Here" href="http://www.2big2send.com/shared.php?token=488b8b61350ef8bf1cdb75efd298de40">Get the Full Code in  a ZIP Here. </a></p>
<p>&#8211; If you are using this script, i would greatly appreciate it if you referenced http://nodstrum.com in your sourcecode <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/02/27/ajaxcontentload/feed/</wfw:commentRss>
		<slash:comments>165</slash:comments>
		</item>
		<item>
		<title>Image Manipulation using PHP and ImageMagicK</title>
		<link>http://www.nodstrum.com/2007/02/06/imagemagick_manipulation/</link>
		<comments>http://www.nodstrum.com/2007/02/06/imagemagick_manipulation/#comments</comments>
		<pubDate>Tue, 06 Feb 2007 17:46:06 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/02/06/imagemagick_manipulation/</guid>
		<description><![CDATA[So there were a couple of problems with my last image processing functions (http://nodstrum.com/2006/12/09/image-manipulation-using-php/). 1. If you were trying to process a massive image &#62; 1024pxÃ—768px it failed. 2. I only accounted for people processing Jpegs. 3. CPU spikes, because of the amount of processing that is being done with the image the CPU is [...]]]></description>
			<content:encoded><![CDATA[<p>So there were a couple of problems with my last image processing functions (<a href="http://nodstrum.com/2006/12/09/image-manipulation-using-php/">http://nodstrum.com/2006/12/09/image-manipulation-using-php/</a>).</p>
<p>1. If you were trying to process a massive image &gt; 1024pxÃ—768px it failed.<br />
2. I only accounted for people processing Jpegs.<br />
3. CPU spikes, because of the amount of processing that is being done with the image the CPU is really taking a hit.<br />
4. The functions were really quite long.</p>
<p>These new function will use ImageMagicK, not all servers have ImageMagicK installed by default, check with your hosting provider.</p>
<p><span id="more-17"></span></p>
<p>So, here are the functions&#8230;</p>
<p><strong>Thumbnail</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> createThumbIMK<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbDir</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newHeight</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// add in the suffix after the '.' dot.</span>
	<span style="color: #000088;">$newNameE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$suffix</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// ImageMagicK doesnt like '/' and 'x' characters in the command line call.</span>
	<span style="color: #000088;">$uploadedImg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$imgPath</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$img</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newThumb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$thumbDir</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newName</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newRes</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newWidth</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newHeight</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// This makes a command line call to ImageMagicK.</span>
  <span style="color: #666666; font-style: italic;">// My path to ImageMagicK Convert is '/usr/lib/php/bin/convert'</span>
  <span style="color: #666666; font-style: italic;">// 'convert' is a program (UNIX) so no forward slash.</span>
	<span style="color: #000088;">$ct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/usr/lib/php/bin/convert -resize <span style="color: #006699; font-weight: bold;">$newRes</span> <span style="color: #006699; font-weight: bold;">$uploadedImg</span> <span style="color: #006699; font-weight: bold;">$newThumb</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$retval</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ct</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Resize</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> createResizedIMK<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbDir</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$by</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// add in the suffix after the '.' dot.</span>
	<span style="color: #000088;">$newNameE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$suffix</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// ImageMagicK doesnt like '/' and 'x' characters in the command line call.</span>
  <span style="color: #666666; font-style: italic;">// And workout the size based on '$by'.</span>
	<span style="color: #000088;">$uploadedImg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$imgPath</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$img</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newResized</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$reduceDir</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newName</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newWidth</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">/</span><span style="color: #000088;">$by</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newHeight</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span><span style="color: #339933;">/</span><span style="color: #000088;">$by</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newRes</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newWidth</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newHeight</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// This makes a command line call to ImageMagicK.</span>
  <span style="color: #666666; font-style: italic;">// My path to ImageMagicK Convert is '/usr/lib/php/bin/convert'</span>
  <span style="color: #666666; font-style: italic;">// 'convert' is a program (UNIX) so no forward slash.</span>
	<span style="color: #000088;">$cr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/usr/lib/php/bin/convert -resize <span style="color: #006699; font-weight: bold;">$newRes</span> <span style="color: #006699; font-weight: bold;">$uploadedImg</span> <span style="color: #006699; font-weight: bold;">$newResized</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$retval</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$cr</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>!! <strong>Important:</strong> you must ensure that when you pass $img to the functions that it has no spaces in it&#8230; here is an example (replacing spaced with &#8216;_&#8217; underscores. Also dont forget to rename the actual file. !!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$imgSafe</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">rename</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dir</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dir</span>/<span style="color: #006699; font-weight: bold;">$imgSafe</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here are some examples.<br />
<a href="http://res.nodstrum.com/imageFunctionsIMK/building_belfast_original.jpg">Building Original (916K (2576&#215;1932))</a><br />
<a href="http://res.nodstrum.com/imageFunctionsIMK/building_belfast_thumbjpg.jpg">Building Thumb (20K (120&#215;90))</a><br />
<a href="http://res.nodstrum.com/imageFunctionsIMK/building_belfast_reduced.jpg">Building Resized and Reduced (71K (515&#215;386))</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/02/06/imagemagick_manipulation/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Transparency in IE6 and Other Browsers :)</title>
		<link>http://www.nodstrum.com/2007/02/02/csstransparency/</link>
		<comments>http://www.nodstrum.com/2007/02/02/csstransparency/#comments</comments>
		<pubDate>Fri, 02 Feb 2007 10:06:44 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dev]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/02/02/csstransparency/</guid>
		<description><![CDATA[This post will cover backgrounds (for DIVs) and transparent images (.PNGs) As we ALL know; IE6 poses far too many challenges for designers, resulting in seperate stylesheets and hacks. I found the need for a transparent background with links on top of it, in Firefox &#38; Safari (and IE7) PNGs are supported, so all worked [...]]]></description>
			<content:encoded><![CDATA[<p>This post will cover backgrounds (for DIVs) and transparent images (.PNGs)</p>
<p>As we ALL know; IE6 poses far too many challenges for designers, resulting in seperate stylesheets and hacks.<br />
I found the need for a transparent background with links on top of it, in Firefox &amp; Safari (and IE7) PNGs are supported, so all worked fine, but when tried with IE6, Yea, there were PROBLEMS! No PNG support and links within the transparent window disappeared.</p>
<p><strong>There are links to the PNGs and Demos at the bottom of the post.</strong></p>
<p>This is the difinitive way to make transparency work with all browsers!</p>
<p><span id="more-14"></span></p>
<p><strong>CSS code for STANDARD supporting browsers (Firefox, Safari).</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.<span style="color: #993333;">transparent</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/blackTransparent80.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>CSS code for IE6 (hack).</strong> this is put in the style-sheet as well.<br />
(The &#8216;*html&#8217; only works on IE and is ignored by all other browsers.)</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span>html .<span style="color: #993333;">transparent</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
filter<span style="color: #3333ff;">:progid</span><span style="color: #3333ff;">:DXImageTransform</span><span style="color: #6666ff;">.Microsoft</span>.AlphaImageLoader<span style="color: #00AA00;">&#40;</span>src<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'images/blackTransparent80.png'</span><span style="color: #00AA00;">,</span> sizingMethod<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'scale'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>This code is the code for the DIV</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;span style=&quot;position: relative; top: 1px; left: 1px;&quot;&gt;
&lt;a href=&quot;http://nodstrum.com&quot;&gt;nodstrum.com&lt;/a&gt;
&lt;/span&gt;
&lt;span style=&quot;position: relative; top: 90px; left: 270px;&quot;&gt;
&lt;a href=&quot;http://blue44.com&quot;&gt;blue44.com&lt;/a&gt;
&lt;/span&gt;
&lt;span style=&quot;position: relative; top: 200px; left: 70px;&quot;&gt;
&lt;a href=&quot;http://teenfirst.com&quot;&gt;teenfirst.com&lt;/a&gt;
&lt;/span&gt;</pre></div></div>

<p>Here are the links to my pre-made transparent backgrounds and the demos.<br />
<a href="http://res.nodstrum.com/ieTransparency/white.html">Transparency Demo &#8211; White</a><br />
<a href="http://res.nodstrum.com/ieTransparency/black.html">Transparency Demo &#8211; Black</a><br />
<a href="http://res.nodstrum.com/ieTransparency/whiteTransparent80.png">White 80% Transparent PNG (1px x 1px)</a><br />
<a href="http://res.nodstrum.com/ieTransparency/blackTransparent80.png">Black 80% Transparent PNG (1px x 1px)</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/02/02/csstransparency/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Calendar System &#8211; Easily using PHP &amp; Script.aculo.us</title>
		<link>http://www.nodstrum.com/2007/01/29/phpcalendar/</link>
		<comments>http://www.nodstrum.com/2007/01/29/phpcalendar/#comments</comments>
		<pubDate>Mon, 29 Jan 2007 21:37:48 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/01/29/phpcalendar/</guid>
		<description><![CDATA[THIS HAS BEEN UPDATED, PLEASE SEE THIS POST: http://nodstrum.com/2007/06/27/mysql-calendar/ Hi, Quite a few people seemed to like my previous tutorial Image Manipulation using PHP, and looking around many of the tutorial sites there are hardly any Calendar systems. Perfect, here is a simple, in calendar terms one&#8230; You&#8217;ll see what i mean. At the bottom [...]]]></description>
			<content:encoded><![CDATA[<p><strong>THIS HAS BEEN UPDATED, PLEASE SEE THIS POST: <a href="http://nodstrum.com/2007/06/27/mysql-calendar/">http://nodstrum.com/2007/06/27/mysql-calendar/</a></strong><a href="http://nodstrum.com/2007/06/27/mysql-calendar/"> </a></p>
<p>Hi,</p>
<p>Quite a few people seemed to like my previous tutorial <a href="http://nodstrum.com/2006/12/09/image-manipulation-using-php/">Image Manipulation using PHP</a>, and looking around many of the tutorial sites there are hardly any Calendar systems. Perfect, here is a simple, in calendar terms one&#8230;<br />
You&#8217;ll see what i mean.</p>
<p><strong>At the bottom of this tutorial there is a link to the ZIP and the test site. </strong></p>
<p>There are 3 main parts, the Javascript, the HTML and the PHP script.<br />
For this tutorial i am making it so you can change the date with the form and it will update the calendar without having to reload the entire page, AJAX style.</p>
<p>First we need the Script.aculo.us library, if you download my zip test file it is already included, but if not go to: http://script.aculo.us</p>
<p><span id="more-16"></span></p>
<p>This is the basic HTML page with the style sheet.<br />
The stylesheet is important because it contains the .calendarFloat part.<br />
The important part is the &lt; div id=&#8221;calendarInternal&#8221; &gt; this is where the calendar will be loaded into, its in its own &lt; div &gt; because we need to clear the float to enclose the calendar and make the box enclose the entire calendar.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&nbsp;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot; /&gt;
&lt;script src=&quot;js/lib/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/src/scriptaculous.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;style&gt;
	.calendarBox {
		position: relative;
		top: 30px;
		margin: 0 auto;
		padding: 5px;
		width: 254px;
		border: 1px solid #000;
	}
&nbsp;
	.calendarFloat {
		float: left;
		width: 31px;
		height: 25px;
		margin: 1px 0px 0px 1px;
		padding: 1px;
		border: 1px solid #000;
	}
&lt;/style&gt;
&lt;p id=&quot;calendar&quot; class=&quot;calendarBox&quot;&gt;&amp;nbsp;&lt;/p&gt;
&nbsp;
&lt;p id=&quot;calendarInternal&quot;&gt;
&nbsp;
&lt;br style=&quot;clear: both&quot; /&gt;</pre></div></div>

<p>Next is the Javascript that has to be added to the Head of the document.<br />
This does the highlighting and loading of the calendar using the script.aculo.us</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">function</span> highlightCalendarCell<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1px solid #999999'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> resetCalendarCell<span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> color<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1px solid #000000'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> startCalendar<span style="color: #009900;">&#40;</span>month<span style="color: #339933;">,</span> year<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'calendarInternal'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rpc.php'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span> postBody<span style="color: #339933;">:</span><span style="color: #3366CC;">'action=startCalendar&amp;month='</span><span style="color: #339933;">+</span>month<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;year='</span><span style="color: #339933;">+</span>year<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The 2nd to last part is the RPC page, its not truly an RPC (remote procedure call) page, i just call it that because it is distinct.<br />
I use a switch statement because my function is normally enclosed in a huge page, so here goes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
	<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'startCalendar'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'month'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'year'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</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: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thisDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thisDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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;">$month</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;p style=&quot;margin-bottom: 3px&quot;&gt;&amp;nbsp;&lt;/p&gt;
&nbsp;
&lt;form name=&quot;changeCalendarDate&quot;&gt;
&lt;select id=&quot;ccMonth&quot; onchange=&quot;startCalendar($F('</span>ccMonth<span style="color: #0000ff;">'), $F('</span>ccYear<span style="color: #0000ff;">'))&quot;&gt;																																																																																																																																			&lt;option value=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$monthMaker</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;										&lt;/select&gt;
&lt;select id=&quot;ccYear&quot; onchange=&quot;startCalendar($F('</span>ccMonth<span style="color: #0000ff;">'), $F('</span>ccYear<span style="color: #0000ff;">'))&quot;&gt;																																																																																																																																								&lt;option value=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;										&lt;/select&gt;
&lt;/form&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Display the week days.</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Mon&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Tue&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Wed&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Thur&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Fri&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #cccccc&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Sat&lt;/span&gt;&lt;/p&gt;
&nbsp;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #cccccc&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Sun&lt;/span&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Show the calendar.</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,&gt;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thisDay</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</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: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$finalDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thisDay</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$today</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$fdf</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$finalDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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;">$month</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thisDay</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$fdf</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</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;">$month</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Skip some cells to take into account for the weekdays.</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$firstDay</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fdf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$skip</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstDay</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$skip</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$skip</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$s</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #000088;">$skip</span><span style="color: #339933;">;</span> <span style="color: #000088;">$s</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;/date(&quot;t&quot;,&gt;
&nbsp;
&lt;p class=&quot;calendarFloat&quot; style=&quot;border: 1px solid #ffffff&quot;&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Make the weekends a darker colour.</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$finalDate</span><span style="color: #009900;">&#41;</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: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$finalDate</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$bgColor</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#CCC'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$bgColor</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#f0f2ff'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
             <span style="color: #666666; font-style: italic;">// == Add any database query here using $finalDate as the timestamp for this date.</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Display the day.</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&nbsp;
&lt;p class=&quot;calendarFloat&quot; id=&quot;calendarDay_'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$thisDay</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; style=&quot;cursor: pointer&quot;&gt;
&nbsp;
onMouseOver=&quot;highlightCalendarCell('</span>calendarDay_<span style="color: #0000ff;">'. $thisDay .'</span><span style="color: #0000ff;">')&quot;
									onMouseOut=&quot;resetCalendarCell('</span>calendarDay_<span style="color: #0000ff;">'. $thisDay .'</span><span style="color: #0000ff;">')&quot;&amp;gt;
						&lt;span style=&quot;position: relative; left: 1px&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$thisDay</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>The final part is the one that ties it all together. This javascript is placed at the bottom of the page, within the &lt; body &gt; tags.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
		startCalendar<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now for a short explaniation&#8230;<br />
If startCalendar(0,0) is called like so, with zeros, it defaults to the current month, if you have a look at the RPC file, at the top, you will notice there is a line that is if $month == 0 and $year == 0, then the date is date(&#8220;m&#8221;); (i think).</p>
<p>Next we are making the form for selecting the month and year, at the same time making the selected month and year (gotten by $month and $year) the current ones in the drop doen boxes.</p>
<p>Now we are just displaying the days of the week so the calendar is readable.<br />
Now the difficult part, determining the timestamp incase we want to use the database.<br />
Skipping some days to take into account days from the previous month, so the 1st of the month starts ont he proper week day, thats a tough one.<br />
Then its just spitting out the calendar.</p>
<p>And here is the Piece De Resistance, if you can call it that&#8230;<br />
<a href="http://res.nodstrum.com/calendar/" target="_blank">http://res.nodstrum.com/calendar/</a></p>
<p>And now for the downloads:<br />
<a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=6">Calendar System ZIP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/01/29/phpcalendar/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Image Manipulation using PHP</title>
		<link>http://www.nodstrum.com/2006/12/09/image-manipulation-using-php/</link>
		<comments>http://www.nodstrum.com/2006/12/09/image-manipulation-using-php/#comments</comments>
		<pubDate>Sat, 09 Dec 2006 14:24:57 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2006/12/09/image-manipulation-using-php/</guid>
		<description><![CDATA[I have been trawling around the internet looking for some simple functions for do basic automated manipulation to some images im using. if you want to skip straight to the examples just to prove im not bulls**ting skip to the bottom Basically i wanted to have these functions: 1. thumbnail 2. resize (actual image) 3. [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trawling around the internet looking for some simple functions for do basic automated manipulation to some images im using.</p>
<p><strong>if you want to skip straight to the examples just to prove im not bulls**ting skip to the bottom</strong></p>
<p>Basically i wanted to have these functions:<br />
1. <strong>thumbnail</strong><br />
2. <strong>resize (actual image)</strong><br />
3. <strong>reduce (image file size)</strong><br />
4. <strong>rotate (by degrees)</strong></p>
<p>Most of the scripts i found couldnt be changed easily to make them do what i wanted&#8230;<br />
So here are what i got working.. and a few instructions&#8230;</p>
<p><span id="more-7"></span></p>
<p><strong>Create a thumbnail</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> createThumbnail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newHeight</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Open the original image.</span>
  <span style="color: #000088;">$original</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error Opening original&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Resample the image.</span>
  <span style="color: #000088;">$tempImg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newHeight</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant create temp image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$original</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;">$newWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newHeight</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant resize copy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Create the new file name.</span>
  <span style="color: #000088;">$newNameE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$suffix</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Save the image.</span>
  <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$newName</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant save image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Clean up.</span>
  <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</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;">$tempImg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>Rotate</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rotateImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$degrees</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #339933;">,</span> <span style="color: #000088;">$save</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Open the original image.</span>
    <span style="color: #000088;">$original</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error Opening original&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Resample the image.</span>
    <span style="color: #000088;">$tempImg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant create temp image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$original</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;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant resize copy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Rotate the image.</span>
    <span style="color: #000088;">$rotate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagerotate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</span><span style="color: #339933;">,</span> <span style="color: #000088;">$degrees</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Save.</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$save</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Create the new file name.</span>
    <span style="color: #000088;">$newNameE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$suffix</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Save the image.</span>
    <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rotate</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$newName</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant save image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Clean up.</span>
    <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</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;">$tempImg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>Resize</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> resizeImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$by</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Open the original image.</span>
    <span style="color: #000088;">$original</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error Opening original (&lt;em&gt;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&lt;/em&gt;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Determine new width and height.</span>
    <span style="color: #000088;">$newWidth</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">/</span><span style="color: #000088;">$by</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$newHeight</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span><span style="color: #339933;">/</span><span style="color: #000088;">$by</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Resample the image.</span>
    <span style="color: #000088;">$tempImg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newHeight</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant create temp image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$original</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;">$newWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newHeight</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant resize copy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Create the new file name.</span>
    <span style="color: #000088;">$newNameE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$suffix</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Save the image.</span>
    <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$newName</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant save image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Clean up.</span>
    <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</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;">$tempImg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>Reduce</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> reduceImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Open the original image.</span>
    <span style="color: #000088;">$original</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error Opening original (&lt;em&gt;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&lt;/em&gt;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$img</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Resample the image.</span>
    <span style="color: #000088;">$tempImg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant create temp image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$original</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;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant resize copy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Create the new file name.</span>
    <span style="color: #000088;">$newNameE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span> <span style="color: #000088;">$suffix</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$newNameE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Save the image.</span>
    <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempImg</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$imgPath</span>/<span style="color: #006699; font-weight: bold;">$newName</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cant save image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Clean up.</span>
    <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</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;">$tempImg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>The simple instructions I used for the examples</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> createThumbnail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-thumb&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rotate</span> <span style="color: #339933;">=</span> rotateImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-rotated&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">270</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$resize</span> <span style="color: #339933;">=</span> resizeImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-resized&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$reduce</span> <span style="color: #339933;">=</span> reduceImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgPath</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-reduced&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">70</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Those are the function calls i used to create the images linked to below.</p>
<p><strong>createThumbnail variables</strong><br />
image file<br />
image file path<br />
suffix to append to the name before the .jpg<br />
thumbnail width<br />
thumbnail height<br />
thumbnail quality</p>
<p><strong>rotateImage variables</strong><br />
image file<br />
image file path<br />
suffix to append to the name before the .jpg<br />
degrees to rotate (anticlockwise i think) by<br />
image quality<br />
save or not (if you wanted to output to a temp to preview, i dont use it, so leave as 1</p>
<p><strong>resize variables</strong><br />
image file<br />
image file path<br />
suffix to append to the name before the .jpg<br />
resize by (i used <strong>2</strong> which i thought was half.. not so hot on the maths)<br />
image quality</p>
<p><strong>reduce variables</strong><br />
image file<br />
image file path<br />
suffix to append to the name before the .jpg<br />
quality (100 best, 0 worst&#8230; Duhh).</p>
<p><strong>Here are the links to my examples</strong><br />
<a href="http://res.nodstrum.com/imageFunctionsGD/jamie_original.jpg">Original File (904k (1840&#215;1232))</a><br />
<a href="http://res.nodstrum.com/imageFunctionsGD/jamie_thumb.jpg">Thumbnail (16k (120&#215;100))</a><br />
<a href="http://res.nodstrum.com/imageFunctionsGD/jamie_reduced.jpg">Resized and Reduced (24k (368&#215;246))</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2006/12/09/image-manipulation-using-php/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
	</channel>
</rss>

