<?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>Andrei DANEASA &#187; PHP</title>
	<atom:link href="http://www.webxpert.ro/andrei/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webxpert.ro/andrei</link>
	<description>Programming, database, security, Oracle, .NET, C#, PHP, Travel</description>
	<lastBuildDate>Tue, 18 Oct 2011 15:42:40 +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>Book review: PHP 5 e-commerce Development by Michael Peacock (Packt Publishing)</title>
		<link>http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/</link>
		<comments>http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 17:53:19 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[michael peacock]]></category>
		<category><![CDATA[packt]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/?p=657</guid>
		<description><![CDATA[PHP is one of my preferred languages. I&#8217;ve been using it for almost 10 years, since version 3, I witnessed the release of 4.0&#8230; in some words: I have a bit of experience. I&#8217;ve been given by Packt one of the latest PHP books they published, called &#8220;PHP 5 e-Commerce Development&#8220;. The title sounds very [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is one of my preferred languages. I&#8217;ve been using it for almost 10 years, since version 3, I witnessed the release of 4.0&#8230; in some words: I have a bit of experience.<br />
I&#8217;ve been given by Packt one of the latest PHP books they published, called &#8220;<a href="http://www.packtpub.com/php-5-e-commerce-development/book">PHP 5 e-Commerce Development</a>&#8220;. The title sounds very promising and I expected to get an update on the latest technologies and techniques related to e-Commerce out of it.</p>
<p><img src="http://www.webxpert.ro/andrei/wp-content/uploads/2010/03/184719964X-243x300.jpg" alt="184719964X" title="184719964X" width="243" height="300" class="aligncenter size-medium wp-image-685" /></p>
<p>First, the book is following what it says in the title, creating one e-Commerce site from the ground. From authentication to discount codes, everything is covered by the book. It touches also some APIs from payment gateways and Google. So who wants to have a ride in knowing how to build an eCommerce site with PHP 5 should read the book.</p>
<p>If you want just the positive feedback you should stop here.<span id="more-657"></span></p>
<p>Secondly, I don&#8217;t think the book has a well defined target, because author&#8217;s own framework is used all over the book and the explanations are not sufficient enough in my opinion. When there are so many frameworks on the market, it&#8217;s a very high chance that the users to use one of these frameworks (not the author&#8217;s one) to build the eShop. In this case most of the code is useless and you&#8217;ll remain just with the explanation of the logic behind. I also expected more specific info on payment processing, SEO, marketing, newsletters, admin alerts, and not necessary all the source code out there. </p>
<p>I reckon I didn&#8217;t read the description, excerpt or anything else about the book before starting to read it, so that&#8217;s why I was a bit dissapointed. The book&#8217;s description on Packt is correct: &#8220;<i>This is a fast-paced tutorial focusing on creating a framework and using it to build an online store through an ongoing case study. Later chapters include examples to illustrate how easily the framework can be adapted for different situations. The framework and code are enhanced and built upon with each chapter, adding more and more functionality. </i>&#8220;. So online store is just a case study, the book is focused on the framework.</p>
<p>However, the book is still very interesting for people that want to create their own in-house light framework and that don&#8217;t want to rely on a fat framework like CodeIgniter, phpCake, ZendFramework.</p>
<p><strong>My conclusion</strong>: a nice reading, 4 stars out of 5, but if you don&#8217;t plan to use the framework presented in the book, then the source code is too much and hard to follow. </p>
<p>****~ (4.0/5)</p>
<p>openSource e-shop solutions: <a href="http://www.prestashop.com">prestaShop</a>, <a href="http://www.oscommerce.com">osCommerce</a>.</p>
<p>Enjoy!</p>
<p><em><strong>Related posts:</strong></em></p>
<li><a href="http://www.webxpert.ro/andrei/2010/01/22/book-review-sql-developer-2-1-by-sue-harper-packt-publishing/">Book review: SQL Developer 2.1 by Sue Harper (Packt Publishing)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2009/10/15/im-going-to-review-onesome-packt-books/">I&#8217;m going to review one/some Packt book(s)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/">Thank you ZendEditor !</a></li>
<li><a href="http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/">Thumbnail generation with PHP tutorial</a></li>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thank you ZendEditor !</title>
		<link>http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/</link>
		<comments>http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 16:21:42 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/?p=314</guid>
		<description><![CDATA[Seems that my thumbnail generation tutorial was somehow appreciated by community and somebody posted an article on Zend Developer Zone describing my tutorial as &#8220;Advanced Thumbnail Trickery with PHP&#8220;. First, thank you! Second, I never had so many visitors coming from the same referred. When I saw my statistics I thought that my internal statistics [...]]]></description>
			<content:encoded><![CDATA[<p>Seems that my <a href="http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/">thumbnail generation tutorial</a> was somehow appreciated by community and somebody posted an article on Zend Developer Zone describing my tutorial as &#8220;<a href="http://devzone.zend.com/article/4162-Advanced-Thumbnail-Trickery-with-PHP">Advanced Thumbnail Trickery with PHP</a>&#8220;. </p>
<p>First, thank you!<br />
Second, I never had so many visitors coming from the same referred. When I saw my statistics I thought that my internal statistics tool went crazy and I checked my google analytics account. Seems that it&#8217;s true.</p>
<p>I promise I will elaborate the topic and make a class with it. I will also try to do the same thing with ImageMagick as a visitor suggested.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thumbnail generation with PHP tutorial</title>
		<link>http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/</link>
		<comments>http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 08:19:25 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[square]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/?p=293</guid>
		<description><![CDATA[No, it&#8217;s not yet another PHP thumbnail generation tutorial! I recently needed a function to: create square thumbnails don&#8217;t crop the initial image, but scale it and fill with white background center the thumbnail in the square call the function in a loop to process an entire folder I found no suitable example and I [...]]]></description>
			<content:encoded><![CDATA[<p>No, it&#8217;s not yet another PHP thumbnail generation tutorial! I recently needed a function to:</p>
<ul>
<li>create <strong>square </strong>thumbnails</li>
<li><strong>don&#8217;t crop</strong> the initial image, but scale it and fill with <strong>white background</strong></li>
<li><strong>center </strong>the thumbnail in the square</li>
<li>call the function in a loop to <strong>process an entire folder</strong></li>
</ul>
<p>I found no suitable example and I decided that instead of digging too much it&#8217;s better to create my own function and a class for it.</p>
<p>Let&#8217;s start with a photo that we need to create a thumbnail for:<br />
<div id="attachment_295" class="wp-caption aligncenter" style="width: 490px"><img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut.jpg" alt="Nice kid, huh?" title="danut" width="480" height="640" class="size-full wp-image-295" /><p class="wp-caption-text">Nice kid, huh?</p></div><br />
&#8230; and what we want to achieve:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut_thumb.jpg" alt="danut_thumb" title="danut_thumb" width="167" height="167" class="aligncenter size-full wp-image-297" /></p>
<hr />
<strong>First step would be the thumbnail generation snippet:</strong><br />
<span id="more-293"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<span class="re0">$square_size</span> = <span class="nu0">167</span>;<br />
<span class="re0">$quality</span> = <span class="nu0">100</span>;<br />
<span class="co1">//get original image attributes</span><br />
<a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span>, <span class="re0">$height</span>, <span class="re0">$type</span>, <span class="re0">$attr</span><span class="br0">&#41;</span> = <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
<span class="re0">$thumb</span>=imagecreatefromjpeg<span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
<span class="re0">$thumb_p</span> = imagecreatetruecolor<span class="br0">&#40;</span><span class="re0">$square_size</span>, <span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$square_size</span>, <span class="re0">$square_size</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;<br />
<span class="co1">//save the file</span><br />
imagejpeg<span class="br0">&#40;</span><span class="re0">$thumb_p</span>,<span class="re0">$thumbs_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span>,<span class="re0">$quality</span><span class="br0">&#41;</span>;</div>
<p>This would be the result:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut1.jpg" alt="danut1" title="danut1" width="167" height="167" class="aligncenter size-full wp-image-306" /><br />
As we can see, <strong>the photo is distorted and we need to scale it</strong>, by adding 2 variables:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="co1">//set dimensions</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$width</span>&gt; <span class="re0">$height</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respect the ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$height</span>/<span class="re0">$width</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span> <span class="kw1">elseif</span><span class="br0">&#40;</span><span class="re0">$height</span>&gt; <span class="re0">$width</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$width</span>/<span class="re0">$height</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
<span class="br0">&#125;</span></div>
<p>We also need to change the <strong>imagecopyresampled </strong>function call to add these 2 new variables:</p>
<div class="dean_ch" style="white-space: wrap;">
imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$width_t</span>, <span class="re0">$height_t</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;</div>
<p>The new result would be:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut2.jpg" alt="danut2" title="danut2" width="167" height="167" class="aligncenter size-full wp-image-307" /><br />
The image is not distorted anymore but <strong>now it&#8217;s not centered</strong>. We need to move the point where the scaled image appears on the thumb to the right with a number of pixels equal to the half of the difference between height and width of the thumb. This offset is implemented also in the <strong>imagecopyresampled </strong>function, the first 2 zeros from the set of 4.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="co1">//set dimensions</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$width</span>&gt; <span class="re0">$height</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respect the ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$height</span>/<span class="re0">$width</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set the offset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$width_t</span>-<span class="re0">$height_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="nu0">0</span>;<br />
<span class="br0">&#125;</span> <span class="kw1">elseif</span><span class="br0">&#40;</span><span class="re0">$height</span>&gt; <span class="re0">$width</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$width</span>/<span class="re0">$height</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="re0">$off_x</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$height_t</span>-<span class="re0">$width_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
<span class="br0">&#125;</span></div>
<p>We also need to change the <strong>imagecopyresampled </strong>function call to add these 2 new variables:</p>
<div class="dean_ch" style="white-space: wrap;">
imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="re0">$off_x</span>, <span class="re0">$off_y</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$width_t</span>, <span class="re0">$height_t</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;</div>
<p>The new thumbnail look like this:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut3.jpg" alt="danut3" title="danut3" width="167" height="167" class="aligncenter size-full wp-image-308" /><br />
It&#8217;s better, the last thing I want is to <strong>set a white background to the thumb</strong> and I&#8217;m done. By default <strong>imagecreatetruecolor </strong>is creating a black canvas with no parameter to change it to white. In order to do this we need to declare a white background and fill the canvas with it <strong>BEFORE </strong>adding the scaled image:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="re0">$bg</span> = imagecolorallocate <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">255</span>, <span class="nu0">255</span>, <span class="nu0">255</span> <span class="br0">&#41;</span>;<br />
imagefill <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$bg</span> <span class="br0">&#41;</span>;</div>
<p>Now it&#8217;s what I want:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut4.jpg" alt="danut4" title="danut4" width="167" height="167" class="aligncenter size-full wp-image-309" /></p>
<p>The whole source code is the following:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">function</span> set_thumb<span class="br0">&#40;</span><span class="re0">$file</span>, <span class="re0">$photos_dir</span>=<span class="st0">&#8216;uploads/photos&#8217;</span>,<span class="re0">$thumbs_dir</span>=<span class="st0">&#8216;uploads/photos/thumbs&#8217;</span>, <span class="re0">$square_size</span>=<span class="nu0">167</span>, <span class="re0">$quality</span>=<span class="nu0">100</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//check if thumb exists</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/file_exists"><span class="kw3">file_exists</span></a><span class="br0">&#40;</span><span class="re0">$thumbs_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//get image info</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span>, <span class="re0">$height</span>, <span class="re0">$type</span>, <span class="re0">$attr</span><span class="br0">&#41;</span> = <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$width</span>&gt; <span class="re0">$height</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respect the ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$height</span>/<span class="re0">$width</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set the offset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$width_t</span>-<span class="re0">$height_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">elseif</span><span class="br0">&#40;</span><span class="re0">$height</span>&gt; <span class="re0">$width</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$width</span>/<span class="re0">$height</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$height_t</span>-<span class="re0">$width_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$thumb</span>=imagecreatefromjpeg<span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$thumb_p</span> = imagecreatetruecolor<span class="br0">&#40;</span><span class="re0">$square_size</span>, <span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//default background is black</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$bg</span> = imagecolorallocate <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">255</span>, <span class="nu0">255</span>, <span class="nu0">255</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagefill <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$bg</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="re0">$off_x</span>, <span class="re0">$off_y</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$width_t</span>, <span class="re0">$height_t</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagejpeg<span class="br0">&#40;</span><span class="re0">$thumb_p</span>,<span class="re0">$thumbs_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span>,<span class="re0">$quality</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p><em><strong>*Note</strong>: Nobody was hurt during this tutorial. The cute dude is <a href="http://rmilitaru.blogspot.com/">Razvan</a>&#8216;s son, Danut.</em></p>
<p>Read also:</p>
<li><a href="http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/">Thank you ZendEditor !</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/09/09/upgrade-oracle-apex-3-2-1-to-4-0-1-on-oracle-database-10g-express-edition-xe/">Upgrade Oracle APEX 3.2.1 to 4.0.1 on Oracle Database 10g Express Edition (XE)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/04/03/oracle-database-11g-release-2-available-on-windows-finally/">Oracle Database 11g Release 2 available on Windows&#8230; finally</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/">Book review: PHP 5 e-commerce Development by Michael Peacock (Packt Publishing)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/03/12/install-subversion-for-vps-cpanel-under-centos/">Install subversion for VPS (cPanel) under CentOS</a></li>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

