<?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: Create Thumbnail with PHP</title>
	<atom:link href="http://www.999tutorials.com/php/create-thumbnail-with-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.999tutorials.com/php/create-thumbnail-with-php/</link>
	<description>999Tutorials.com - Your Tutorial Spot</description>
	<lastBuildDate>Fri, 05 Mar 2010 07:35:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mark</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-6035</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 04 Mar 2010 22:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-6035</guid>
		<description>How about adding this should allow you to deal with all image types
$ext = substr(strrchr($imageName, &#039;.&#039;), 1);
if ($ext == &quot;png&quot;) {$srcext = imagecreatefrompng(&quot;$imageDirectory/$imageName&quot;);goto run;}
if ($ext == &quot;jpg&quot;) {$srcext = imagecreatefromjpeg(&quot;$imageDirectory/$imageName&quot;);goto run;}
if ($ext == &quot;bmp&quot;) {$srcext = imagecreatefrombmp(&quot;$imageDirectory/$imageName&quot;);goto run;}
if ($ext == &quot;gif&quot;) {$srcext = imagecreatefromgif(&quot;$imageDirectory/$imageName&quot;);goto run;}
run:
$srcImg = $srcext;</description>
		<content:encoded><![CDATA[<p>How about adding this should allow you to deal with all image types<br />
$ext = substr(strrchr($imageName, &#8216;.&#8217;), 1);<br />
if ($ext == &#8220;png&#8221;) {$srcext = imagecreatefrompng(&#8220;$imageDirectory/$imageName&#8221;);goto run;}<br />
if ($ext == &#8220;jpg&#8221;) {$srcext = imagecreatefromjpeg(&#8220;$imageDirectory/$imageName&#8221;);goto run;}<br />
if ($ext == &#8220;bmp&#8221;) {$srcext = imagecreatefrombmp(&#8220;$imageDirectory/$imageName&#8221;);goto run;}<br />
if ($ext == &#8220;gif&#8221;) {$srcext = imagecreatefromgif(&#8220;$imageDirectory/$imageName&#8221;);goto run;}<br />
run:<br />
$srcImg = $srcext;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-4247</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 29 Dec 2009 13:59:17 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-4247</guid>
		<description>Looks great. It will help a lot of people! Let me know if you are interested in writing guest posts at 999tutorials.com!</description>
		<content:encoded><![CDATA[<p>Looks great. It will help a lot of people! Let me know if you are interested in writing guest posts at 999tutorials.com!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damic</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-4176</link>
		<dc:creator>Damic</dc:creator>
		<pubDate>Sun, 27 Dec 2009 13:09:09 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-4176</guid>
		<description>Mine code, creates thumbnails from gif/jpg/png

function createthumb($File_In,$thumb_x,$Path_Out)
{
	//select img type
	$type=substr($File_In,strlen($File_In)-3,3);
	switch ($type)
	{
	default:
	{
		$img_in = @imagecreatefromjpeg($File_In);
		break;
	}
	case &#039;gif&#039;:
	{
		$img_in = @imagecreatefromgif($File_In);
		break;
	}
	case &#039;png&#039;:
	{
		$img_in = @imagecreatefrompng($File_In);
		break;
	}
	}
	if($img_in==&#039;&#039;){return;}

	if(imagesx($img_in)&gt;$thumb_x)
	{
		$thumb_y=imagesy($img_in)/(imagesx($img_in)/$thumb_x);
	}else{
		$thumb_y=imagesy($img_in);
		$thumb_x=imagesx($img_in);
	}

	$img_out = @imagecreatetruecolor($thumb_x, $thumb_y);

	imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
	imageinterlace($img_out,1) ;
	imagejpeg($img_out, $Path_Out, 50);
//destroy the tmp images
	imagedestroy($img_out);
	imagedestroy($img_in);
}

Still only got a problem with the png&#039;s</description>
		<content:encoded><![CDATA[<p>Mine code, creates thumbnails from gif/jpg/png</p>
<p>function createthumb($File_In,$thumb_x,$Path_Out)<br />
{<br />
	//select img type<br />
	$type=substr($File_In,strlen($File_In)-3,3);<br />
	switch ($type)<br />
	{<br />
	default:<br />
	{<br />
		$img_in = @imagecreatefromjpeg($File_In);<br />
		break;<br />
	}<br />
	case &#8216;gif&#8217;:<br />
	{<br />
		$img_in = @imagecreatefromgif($File_In);<br />
		break;<br />
	}<br />
	case &#8216;png&#8217;:<br />
	{<br />
		$img_in = @imagecreatefrompng($File_In);<br />
		break;<br />
	}<br />
	}<br />
	if($img_in==&#8221;){return;}</p>
<p>	if(imagesx($img_in)&gt;$thumb_x)<br />
	{<br />
		$thumb_y=imagesy($img_in)/(imagesx($img_in)/$thumb_x);<br />
	}else{<br />
		$thumb_y=imagesy($img_in);<br />
		$thumb_x=imagesx($img_in);<br />
	}</p>
<p>	$img_out = @imagecreatetruecolor($thumb_x, $thumb_y);</p>
<p>	imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));<br />
	imageinterlace($img_out,1) ;<br />
	imagejpeg($img_out, $Path_Out, 50);<br />
//destroy the tmp images<br />
	imagedestroy($img_out);<br />
	imagedestroy($img_in);<br />
}</p>
<p>Still only got a problem with the png&#8217;s</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KC</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-2956</link>
		<dc:creator>KC</dc:creator>
		<pubDate>Wed, 11 Nov 2009 15:59:05 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-2956</guid>
		<description>Thanks for the corrected code,I always follow this site whenever its required and will continue to do that...</description>
		<content:encoded><![CDATA[<p>Thanks for the corrected code,I always follow this site whenever its required and will continue to do that&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pico RG</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-2423</link>
		<dc:creator>Pico RG</dc:creator>
		<pubDate>Fri, 09 Oct 2009 22:05:52 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-2423</guid>
		<description>Thanks for this piece of code, I really appreciate it.</description>
		<content:encoded><![CDATA[<p>Thanks for this piece of code, I really appreciate it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-1715</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sat, 05 Sep 2009 14:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-1715</guid>
		<description>Thanks a lot Scott for taking the time to improve the code!
If you are interested we are always looking for guest bloggers at 999tutorials!?!</description>
		<content:encoded><![CDATA[<p>Thanks a lot Scott for taking the time to improve the code!<br />
If you are interested we are always looking for guest bloggers at 999tutorials!?!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-1707</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Sat, 05 Sep 2009 04:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-1707</guid>
		<description>Here is the corrected code for anyone who needs it.

function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth)
{
$srcImg       = imagecreatefromjpeg(&quot;$imageDirectory/$imageName&quot;);
$origWidth    = imagesx($srcImg);
$origHeight   = imagesy($srcImg);


$ratio        = $origWidth / $thumbWidth;
$thumbHeight  = $origHeight / $ratio;

$thumbImg     = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);

imagejpeg($thumbImg, &quot;$thumbDirectory/$imageName&quot;);
}

***notice the &quot;imagecopyresized&quot; now contains ...$thumbWidth, $thumbHeight, $origWidth, $origHeight); which is the correct way to resize, not crop the image.

I also changed imagecreate to imagecreatetruecolor because the quality is better.

Hope this helps.

God Bless

Scott</description>
		<content:encoded><![CDATA[<p>Here is the corrected code for anyone who needs it.</p>
<p>function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth)<br />
{<br />
$srcImg       = imagecreatefromjpeg(&#8220;$imageDirectory/$imageName&#8221;);<br />
$origWidth    = imagesx($srcImg);<br />
$origHeight   = imagesy($srcImg);</p>
<p>$ratio        = $origWidth / $thumbWidth;<br />
$thumbHeight  = $origHeight / $ratio;</p>
<p>$thumbImg     = imagecreatetruecolor($thumbWidth, $thumbHeight);<br />
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);</p>
<p>imagejpeg($thumbImg, &#8220;$thumbDirectory/$imageName&#8221;);<br />
}</p>
<p>***notice the &#8220;imagecopyresized&#8221; now contains &#8230;$thumbWidth, $thumbHeight, $origWidth, $origHeight); which is the correct way to resize, not crop the image.</p>
<p>I also changed imagecreate to imagecreatetruecolor because the quality is better.</p>
<p>Hope this helps.</p>
<p>God Bless</p>
<p>Scott</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-1209</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 12 Aug 2009 19:31:27 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-1209</guid>
		<description>I was looking for this</description>
		<content:encoded><![CDATA[<p>I was looking for this</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-752</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 08 Jul 2009 07:39:12 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-752</guid>
		<description>Thanks for the correction!
We will soon start publishing new tutorials with higher quality. These are old and should e rewritten, but hopefully they are useful for some basic stuff!</description>
		<content:encoded><![CDATA[<p>Thanks for the correction!<br />
We will soon start publishing new tutorials with higher quality. These are old and should e rewritten, but hopefully they are useful for some basic stuff!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dzovan</title>
		<link>http://www.999tutorials.com/php/create-thumbnail-with-php/comment-page-1/#comment-511</link>
		<dc:creator>dzovan</dc:creator>
		<pubDate>Fri, 19 Jun 2009 14:45:21 +0000</pubDate>
		<guid isPermaLink="false">http://new.999tutorials.com/?p=35#comment-511</guid>
		<description>You have an error in the code.
It should be like this:

1. $thumbHeight = $origHeight / $ratio; 

And it makes a thumb from the top left part of your picture not from the whole pic.</description>
		<content:encoded><![CDATA[<p>You have an error in the code.<br />
It should be like this:</p>
<p>1. $thumbHeight = $origHeight / $ratio; </p>
<p>And it makes a thumb from the top left part of your picture not from the whole pic.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
