<?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>Tips for Twits&#187; image</title>
	<atom:link href="http://t.wits.sg/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://t.wits.sg</link>
	<description>WARNING: excessive use of this site will increase MP at the expense of HP</description>
	<lastBuildDate>Tue, 12 Jul 2011 15:09:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>10 Good (Free and Legal) Source for Photos and Images</title>
		<link>http://t.wits.sg/2009/08/25/10-free-and-legal-photo-source/</link>
		<comments>http://t.wits.sg/2009/08/25/10-free-and-legal-photo-source/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 04:29:33 +0000</pubDate>
		<dc:creator>donald</dc:creator>
				<category><![CDATA[quick picks]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[icon]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[legal]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[stock]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=353</guid>
		<description><![CDATA[Respect others work. Get legal stock photos legally. They can often be free too!]]></description>
			<content:encoded><![CDATA[<p>Days of text sites are long over. Nowadays, you can hardly find a good site without the use of appropriate photos, images and artwork. However, some web designer resort into using others&#8217; work by using google image search. Using those images is often illegal and they are not the best images anyway. Here are a dozen sites that are better and legal.</p>
<p><strong>1. Flickr Creative Commons</strong></p>
<p>One of the site which I visited often for good quality photo is <a href="http://www.flickr.com/" target="_blank">Flickr</a>. It has a huge selection of photos mane of which are protected under the <a title="Creative Commons" href="http://www.authortechtips.com/tag/creative-commons/">Creative Commons</a> which means you can use them legally as long as you attribute the photographer.</p>
<p><strong>2. Stock Exchange</strong></p>
<p>I also frequent  <a title="free stock photos" href="http://www.sxc.hu/" target="_blank">sxc.hu</a> for stock photo as it is the best I have used thus far. But be careful. The first row are premium photos and it cost money. Clicking on them will take you to a different site where you have to pay.</p>
<p><strong>3. IconsPedia.com</strong></p>
<p>If you are looking for icons to doll up your site, <a title="Free Icons" href="http://www.iconspedia.com/" target="_blank">Icons Predia</a> is the place to go. If you want to add a cool Twitter Bird to your website, this is the first place to look.</p>
<p><strong>4. EveryStockPhoto.com</strong></p>
<p><a title="Every Stock Photo" href="http://www.everystockphoto.com/" target="_blank">Every Stock Photo</a> searches several other stock image sites for you. Well, it literally search all the photos regardless of &#8216;appropriateness&#8217;. Hence, you might be in for some &#8216;dirty treats’.</p>
<p><strong>5. NASA</strong></p>
<p>At Savant Degrees, many of us are geeks, so we talk about science fiction, spaceships among other things. I’m not sure how this happened but if the U.S. government takes a photo they often release it into the public domain. If you want high quality technology or space photos you can’t do much better than <a href="http://www.nasa.gov/multimedia/index.html" target="_blank">NASA</a>.</p>
<p><strong>6. FreeDigitalPhotos.net</strong></p>
<p><a href="http://www.freedigitalphotos.net/" target="_blank">Freedigitalphotos.net</a> has high quality photos but the selection is not great and the terms of use require a link back to use the photo for free.</p>
<p><strong>7. FreeStockPhotos.com</strong></p>
<p>Not only does <a title="Free Stock Photos" href="http://freestockphotos.com/" target="_blank">Free Stock Photos</a> have some great nature photos it also has a list of over a dozen other free stock photo sources.</p>
<p><strong>8. MorgueFile.com</strong></p>
<p><a title="Morgue File" href="http://www.morguefile.com/" target="_blank">Morgue File</a> has many photos that you are free to use commercially without attributing the photographer. However, they are not exactly stock photos but more of good snapshots.</p>
<p><strong>9. StockVault.net</strong></p>
<p><a title="Stock Vault" href="http://www.stockvault.net/" target="_blank">StockVault</a> has 13,000+ high quality stock photos. The photos are high quality but low selection. The site does not offer safe search so use it at your own risk.</p>
<p><strong>10. HistoricalStockPhotos.com</strong></p>
<p>If you want vintage photos <a href="http://www.historicalstockphotos.com/">Historical Stock Photos</a> is the site for you. Colorwise, don’t expect too much.</p>
<p>Hope this post help! Do recommend more sites by leaving a comment below!</p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/08/25/10-free-and-legal-photo-source/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HOWTO: PHP image resize, centered and cropped</title>
		<link>http://t.wits.sg/2009/02/07/howto-php-image-resize-centered-and-cropped/</link>
		<comments>http://t.wits.sg/2009/02/07/howto-php-image-resize-centered-and-cropped/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 18:07:25 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[resize]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=19</guid>
		<description><![CDATA[Sorry for not posting in such a long time folks, i just came back from the Pegasus galaxy. While working on a Joomla! 1.5 project, we had to develop a function to crop and resize images for obvious content management and aesthetic reasons. So i gathered around some good sources on PHP.net and wrote the [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for not posting in such a long time folks, i just came back from the Pegasus galaxy. While working on a Joomla! 1.5 project, we had to develop a function to crop and resize images for obvious content management and aesthetic reasons. So i gathered around some good sources on PHP.net and wrote the following class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ImageHelper <span style="color: #009900;">&#123;</span>
&nbsp;
	static <span style="color: #000000; font-weight: bold;">function</span> treatFilename<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$newfilename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$newfilename</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;">$newfilename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$newfilename</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	static <span style="color: #000000; font-weight: bold;">function</span> isPotrait<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #339933;">!</span>ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">isLandscape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	static <span style="color: #000000; font-weight: bold;">function</span> isLandscape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$size</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$srcimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	static <span style="color: #000000; font-weight: bold;">function</span> resizeImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</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> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$srcpathinfo</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$srcext</span> 		<span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcpathinfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extension'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$destpathinfo</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$destimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$destext</span> 		<span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$destpathinfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extension'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$size</span> 			<span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$srcimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				<span style="color: #666666; font-style: italic;">// Get the size of the original image into an array [0]=&gt; width, [1]=&gt; height</span>
		<span style="color: #000088;">$image</span>			<span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$canvas</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><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// Prepare canvas</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Create a new image in the memory from the file </span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'wbmp'</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'bmp'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromwbmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</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: #0000ff;">'jpg'</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpeg'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</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: #0000ff;">'png'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</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: #0000ff;">'gif'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromgif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</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: #0000ff;">'xpm'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> imagecreatefromxpm<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
				<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Calculate dimensions</span>
		<span style="color: #000088;">$widthratio</span>		<span style="color: #339933;">=</span> <span style="color: #000088;">$size</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: #000088;">$width</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$heightratio</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$size</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: #000088;">$height</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$dimensions</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
						<span style="color: #0000ff;">'ratio'</span> 			<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$widthratio</span><span style="color: #339933;">,</span>
						<span style="color: #0000ff;">'source_cropwidth'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
						<span style="color: #0000ff;">'source_cropheight'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
						<span style="color: #0000ff;">'source_offsetx'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
						<span style="color: #0000ff;">'source_offsety'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
						<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$heightratio</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$widthratio</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ratio'</span><span style="color: #009900;">&#93;</span> 			<span style="color: #339933;">=</span> <span style="color: #000088;">$heightratio</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// let say image is 1200*800, then:</span>
		<span style="color: #666666; font-style: italic;">// widthratio = 1200/400 = 3</span>
		<span style="color: #666666; font-style: italic;">// heightratio = 800/300 = 2.66</span>
		<span style="color: #666666; font-style: italic;">// since there is less height than width, the max scale we can do is 2.66, then</span>
		<span style="color: #666666; font-style: italic;">// the targetwidth to crop = 400 * 2.66</span>
		<span style="color: #666666; font-style: italic;">// the targetheight to crop = 300 * 2.66</span>
		<span style="color: #666666; font-style: italic;">// the offset width = (1200 - (2.66 * 400))/2 = 68</span>
		<span style="color: #666666; font-style: italic;">// the offset height = (800 - (2.66 * 300))/2 = 1</span>
&nbsp;
		<span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_width'</span><span style="color: #009900;">&#93;</span> 		<span style="color: #339933;">=</span> <span style="color: #000088;">$size</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: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_height'</span><span style="color: #009900;">&#93;</span> 		<span style="color: #339933;">=</span> <span style="color: #000088;">$size</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: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropwidth'</span><span style="color: #009900;">&#93;</span> 	<span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropheight'</span><span style="color: #009900;">&#93;</span> 	<span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsetx'</span><span style="color: #009900;">&#93;</span> 		<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</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: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropwidth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsety'</span><span style="color: #009900;">&#93;</span> 		<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</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: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropheight'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</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;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsetx'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsety'</span><span style="color: #009900;">&#93;</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;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropwidth'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropheight'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$destext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpeg'</span><span style="color: #339933;">:</span>
				<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</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: #0000ff;">'png'</span><span style="color: #339933;">:</span>
				<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</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: #0000ff;">'gif'</span><span style="color: #339933;">:</span>
				<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</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: #0000ff;">'wbmp'</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'bmp'</span><span style="color: #339933;">:</span>
				<span style="color: #990000;">imagewbmp</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</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;">$image</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<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: #009900;">&#125;</span></pre></div></div>

<div class="contentblock">
use treatFilename to remove those pesky spaces, then use isPotrait or isLandscape to determine the orientation of the picture, then perform your resize accordingly. If your uploaded file input was called <em>ulimage</em>, then the code to resize your image would be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$width</span> 		<span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$height</span> 		<span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ulimage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><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: #000088;">$targetfilename</span>	<span style="color: #339933;">=</span> ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">treatFilename</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;_&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ulimage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ulimage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/tmp/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ulimage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">resizeImage</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/tmp/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #339933;">@</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ulimage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/tmp/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$targetfilename</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><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The reason you need to save the file first is for the imageResize function to infer the image type off its extension. I hadnt bothered to create an image type override. <img src='http://t.wits.sg/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />
</div>
<div class="contentblock">
<strong>Get the source here: <a href="http://t.wits.sg/misc/imageResize/ImageHelper.txt" target="_blank">ImageHelper.php</a><br />
or view the demo <a href="http://t.wits.sg/misc/imageResize/demo.php" target="_blank">here</a></strong>
</div>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/02/07/howto-php-image-resize-centered-and-cropped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

