<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Making &amp; Cropping Thumbnails Square Using PHP &amp; GD</title>
	<atom:link href="http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/feed/" rel="self" type="application/rss+xml" />
	<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/</link>
	<description>Coding Tutorials, hints &#38; tips in PHP, jQuery, CSS &#38; HTML</description>
	<lastBuildDate>Tue, 07 Sep 2010 01:40:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Someone will always do it better. &#171; Monitor Meets Window Blog</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17526</link>
		<dc:creator>Someone will always do it better. &#171; Monitor Meets Window Blog</dc:creator>
		<pubDate>Sat, 03 Jul 2010 18:44:50 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17526</guid>
		<description>[...] http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/" rel="nofollow">http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Writing Text On An Image With GD &#8226; Return True</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17155</link>
		<dc:creator>Writing Text On An Image With GD &#8226; Return True</dc:creator>
		<pubDate>Fri, 18 Jun 2010 21:11:51 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17155</guid>
		<description>[...] easily integrate this code into a uploader by using parts of the code from my previous tutorial on how to make square thumbnails. You could also replace the header() &amp; imagejpeg() functions here for the ones used in the [...]</description>
		<content:encoded><![CDATA[<p>[...] easily integrate this code into a uploader by using parts of the code from my previous tutorial on how to make square thumbnails. You could also replace the header() &amp; imagejpeg() functions here for the ones used in the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Robinson</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17063</link>
		<dc:creator>Paul Robinson</dc:creator>
		<pubDate>Sun, 13 Jun 2010 22:30:21 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17063</guid>
		<description>No problems. If you could email me the code I&#039;ll add it to the post tomorrow, that&#039;s assuming you don&#039;t mind of course. ;)</description>
		<content:encoded><![CDATA[<p>No problems. If you could email me the code I&#8217;ll add it to the post tomorrow, that&#8217;s assuming you don&#8217;t mind of course. <img src='http://return-true.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17062</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Sun, 13 Jun 2010 22:25:42 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17062</guid>
		<description>Rest of the code for those who are interested:



Paul if it fills up your blog too much you can delete the post, thanks for your reponse</description>
		<content:encoded><![CDATA[<p>Rest of the code for those who are interested:</p>
<p>Paul if it fills up your blog too much you can delete the post, thanks for your reponse</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17061</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Sun, 13 Jun 2010 22:22:10 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17061</guid>
		<description>sorry there´s more code but didn´t fit</description>
		<content:encoded><![CDATA[<p>sorry there´s more code but didn´t fit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17060</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Sun, 13 Jun 2010 22:19:55 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17060</guid>
		<description>Got it working:
&lt;?php
$folder=$_GET[&#039;folder&#039;];
$thisdir = getcwd();
if (!file_exists($thisdir .&quot;/&quot;.&quot;$folder/thumbs&quot;)) {
mkdir($thisdir .&quot;/&quot;.&quot;$folder/thumbs&quot; , 0777);}

function returnimages($dirname=&quot;&quot;) {
$pattern=&quot;(\.jpg$)&#124;(\.png$)&#124;(\.jpeg$)&#124;(\.gif$)&quot;; //valid image extensions

$handle  = opendir($dirname);
while (false !== ($filename = readdir($handle))) {
if(eregi($pattern, $filename)){ //if this file is a valid image
    $files[] = $filename;}
}
if (count($files)0) {
sort($files);}

$curimage=0;

while($curimage !== count($files)){
				$cropfile=$dirname.&#039;/&#039;.$files[$curimage];echo $cropfile;
				$source_img = @imagecreatefromjpeg($cropfile); //Create a copy of our image for our thumbnails...
				if (!$source_img) {
				    echo &quot;could not create image handle&quot;;
				    exit(0);
				}
				$new_w = 120;
				$new_h = 120;
	 
				$orig_w = imagesx($source_img);
				$orig_h = imagesy($source_img);
	 
				$w_ratio = ($new_w / $orig_w);
				$h_ratio = ($new_h / $orig_h);
	 			
				if ($orig_w &gt; $orig_h ) {//landscape from here new
				$crop_w = round($orig_w * $h_ratio);
				$crop_h = $new_h;
				$src_x = ceil( ( $orig_w - $orig_h ) / 2 );
				$src_y = 0;
				} elseif ($orig_w </description>
		<content:encoded><![CDATA[<p>Got it working:<br />
&lt;?php<br />
$folder=$_GET[&#039;folder&#039;];<br />
$thisdir = getcwd();<br />
if (!file_exists($thisdir .&quot;/&quot;.&quot;$folder/thumbs&quot;)) {<br />
mkdir($thisdir .&quot;/&quot;.&quot;$folder/thumbs&quot; , 0777);}</p>
<p>function returnimages($dirname=&quot;&quot;) {<br />
$pattern=&quot;(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)&quot;; //valid image extensions</p>
<p>$handle  = opendir($dirname);<br />
while (false !== ($filename = readdir($handle))) {<br />
if(eregi($pattern, $filename)){ //if this file is a valid image<br />
    $files[] = $filename;}<br />
}<br />
if (count($files)0) {<br />
sort($files);}</p>
<p>$curimage=0;</p>
<p>while($curimage !== count($files)){<br />
				$cropfile=$dirname.&#8217;/&#8217;.$files[$curimage];echo $cropfile;<br />
				$source_img = @imagecreatefromjpeg($cropfile); //Create a copy of our image for our thumbnails&#8230;<br />
				if (!$source_img) {<br />
				    echo &#8220;could not create image handle&#8221;;<br />
				    exit(0);<br />
				}<br />
				$new_w = 120;<br />
				$new_h = 120;</p>
<p>				$orig_w = imagesx($source_img);<br />
				$orig_h = imagesy($source_img);</p>
<p>				$w_ratio = ($new_w / $orig_w);<br />
				$h_ratio = ($new_h / $orig_h);</p>
<p>				if ($orig_w &gt; $orig_h ) {//landscape from here new<br />
				$crop_w = round($orig_w * $h_ratio);<br />
				$crop_h = $new_h;<br />
				$src_x = ceil( ( $orig_w &#8211; $orig_h ) / 2 );<br />
				$src_y = 0;<br />
				} elseif ($orig_w</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17058</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Sun, 13 Jun 2010 22:13:28 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17058</guid>
		<description>Got it, thanks</description>
		<content:encoded><![CDATA[<p>Got it, thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Robinson</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17057</link>
		<dc:creator>Paul Robinson</dc:creator>
		<pubDate>Sun, 13 Jun 2010 21:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17057</guid>
		<description>I&#039;m not sure. I&#039;ve never tried to resize images from a directory rather than an upload.

From looking at the little bit of code you have wrote I&#039;m not sure how you are going about it, but I would think a normal loop through files &amp; passing the path to the image to &lt;code&gt;imagecreatefromjpeg()&lt;/code&gt; would work.

If it doesn&#039;t you could always take off the &#039;@&#039; to see what error it&#039;s throwing back and work from there. I&#039;d give it a go, but I don&#039;t have access to my localhost at the moment to test it out.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure. I&#8217;ve never tried to resize images from a directory rather than an upload.</p>
<p>From looking at the little bit of code you have wrote I&#8217;m not sure how you are going about it, but I would think a normal loop through files &#038; passing the path to the image to <code>imagecreatefromjpeg()</code> would work.</p>
<p>If it doesn&#8217;t you could always take off the &#8216;@&#8217; to see what error it&#8217;s throwing back and work from there. I&#8217;d give it a go, but I don&#8217;t have access to my localhost at the moment to test it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-17056</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Sun, 13 Jun 2010 21:28:32 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-17056</guid>
		<description>Great script, I used it for an upload form in a gallery, but now I´m trying to change the first bit to make it work as a batch script for an entire directory.  @imagecreatefromjpeg($files[$curimage]) doesn´t work. Any idea? Thanks in advance</description>
		<content:encoded><![CDATA[<p>Great script, I used it for an upload form in a gallery, but now I´m trying to change the first bit to make it work as a batch script for an entire directory.  @imagecreatefromjpeg($files[$curimage]) doesn´t work. Any idea? Thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Robinson</title>
		<link>http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/comment-page-1/#comment-16927</link>
		<dc:creator>Paul Robinson</dc:creator>
		<pubDate>Thu, 03 Jun 2010 13:05:38 +0000</pubDate>
		<guid isPermaLink="false">http://return-true.com/?p=533#comment-16927</guid>
		<description>No problem. Glad it helped you out. ;)</description>
		<content:encoded><![CDATA[<p>No problem. Glad it helped you out. <img src='http://return-true.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
