


<?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>Learn DooPHP &#187; DooGdImage</title>
	<atom:link href="http://learn.doophp.com/tag/doogdimage/feed/" rel="self" type="application/rss+xml" />
	<link>http://learn.doophp.com</link>
	<description>Learn DooPHP - a high performance MVC based PHP framework</description>
	<lastBuildDate>Thu, 18 Aug 2011 19:47:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Upload and Resize Pictures with DooGdImage</title>
		<link>http://learn.doophp.com/2010/01/upload-and-resize-pictures-with-doogdimage/</link>
		<comments>http://learn.doophp.com/2010/01/upload-and-resize-pictures-with-doogdimage/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 04:19:51 +0000</pubDate>
		<dc:creator>Leng</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[DooGdImage]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[image resize]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://learn.doophp.com/?p=186</guid>
		<description><![CDATA[<p>First you must have an upload form in your HTML, notice that the file input field in the form below is <strong>profile_pic</strong></p>
<pre class="brush: php;">&#60;form action=&#34;/uploadme&#34; method=&#34;post&#34; enctype=&#34;multipart/form-data&#34; name=&#34;upload-photo&#34;&#62;
 &#60;input name=&#34;profile_pic&#34; type=&#34;file&#34; /&#62;
 &#60;input type=&#34;submit&#34; value=&#34;submit&#34;/&#62;
&#60;/form&#62;
</pre>
<p>In Controller, create an instance of <strong>DooGdImage</strong>, along with the upload/source path and the path to save your resized pictures:</p>
<pre class="brush: php;">
 Doo::loadHelper('DooGdImage');
 //upload/source path, and output saved path
 $gd = new DooGdImage('/var/www/uploaded/', '/var/www/resized_pic/');
</pre>
<p>Call uploadImage() to save the uploaded file with a new name. The example below save the picture with the date as file name, <strong>img_20100104203245.jpg</strong></p>
<pre class="brush: php;">$uploadImg = $gd-&#62;uploadImage('profile_pic', 'img_' .date('Ymdhis'));
</pre>
<p>Before your resize the picture, you can set the quality, generated image type and file name suffix (optional)</p>
<pre class="brush: php;">
 $gd-&#62;generatedQuality = 85;
 $uploadImage-&#62;generatedType=&#34;jpg&#34;;

 //This thumbnail is 46x46 pixels, resize adaptively (perfect 46x46 crop from center)
 //Pic name is img_201001011200_46x46.jpg
 $gd-&#62;thumbSuffix = '_46x46';
 $gd-&#62;adaptiveResize($uploadImg,46,46);
</pre>
<p>You can use createThumb/createSquare to resize the pictures too.</p>
<pre class="brush: php;">
 //Resize propotionally (so will not be perfect 75x75 depends on the image ratio, no cropping done)
 //Pic name is img_201001011200_75x75.jpg
 $gd-&#62;thumbSuffix = '_75x75';
 $gd-&#62;createThumb($uploadImg, 75, 75);
</pre>
<p>Some updates*</p>
<p>You can validate if the uploaded images meet your requirements by using checkImageType(), checkImageSize() and checkImageExtension()</p>
<ul>
<li><strong>checkImageType()</strong> &#8211; check if image mime type is in the allowed list. Default: JPEGs, GIFs and PNGs</li>
<li><strong>checkImageExtension()</strong> &#8211; check if image file extension is in the allowed list.</li></ul>]]></description>
		<wfw:commentRss>http://learn.doophp.com/2010/01/upload-and-resize-pictures-with-doogdimage/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
