<?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: PHP-GD: Resize Transparent Image PNG &amp; GIF</title>
	<atom:link href="http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/</link>
	<description>Fight for what you belive in</description>
	<lastBuildDate>Thu, 02 Feb 2012 06:38:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Adam Šorfa</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-40628</link>
		<dc:creator>Adam Šorfa</dc:creator>
		<pubDate>Thu, 26 Jan 2012 14:56:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-40628</guid>
		<description>This example works only with PNG images. Background of my transparent GIF images are still black. can someone help me please?</description>
		<content:encoded><![CDATA[<p>This example works only with PNG images. Background of my transparent GIF images are still black. can someone help me please?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-40281</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Mon, 16 Jan 2012 03:53:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-40281</guid>
		<description>Oh man! I&#039;ve been trying to find a fix for this for months and months for our WordPress blog.
The fix offered at the top didn&#039;t do it, Benjamin&#039;s fix did the trick. I think the problem is that GIF and PNG8 have different pallette numbers for the transparent, which wasn&#039;t being considered by earlier fixes?
Sooo pleased to see this problem dealt with once and for all.</description>
		<content:encoded><![CDATA[<p>Oh man! I&#8217;ve been trying to find a fix for this for months and months for our WordPress blog.<br />
The fix offered at the top didn&#8217;t do it, Benjamin&#8217;s fix did the trick. I think the problem is that GIF and PNG8 have different pallette numbers for the transparent, which wasn&#8217;t being considered by earlier fixes?<br />
Sooo pleased to see this problem dealt with once and for all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lu Cila</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-38176</link>
		<dc:creator>Lu Cila</dc:creator>
		<pubDate>Tue, 06 Dec 2011 16:03:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-38176</guid>
		<description>Bien vos! thanks</description>
		<content:encoded><![CDATA[<p>Bien vos! thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Pons</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-37574</link>
		<dc:creator>Olivier Pons</dc:creator>
		<pubDate>Sat, 12 Nov 2011 11:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-37574</guid>
		<description>You saved my day!</description>
		<content:encoded><![CDATA[<p>You saved my day!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timension &#187; Fix GIF images&#8217; black background in Wordpress</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-37504</link>
		<dc:creator>Timension &#187; Fix GIF images&#8217; black background in Wordpress</dc:creator>
		<pubDate>Tue, 08 Nov 2011 06:16:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-37504</guid>
		<description>[...] http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/" rel="nofollow">http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjamin</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-37131</link>
		<dc:creator>Benjamin</dc:creator>
		<pubDate>Fri, 21 Oct 2011 13:40:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-37131</guid>
		<description>I don&#039;t know if all problems are solved, but here are my changes based on the initial script, to make everything (PNG, GIF) work well:

$new_image = imagecreatetruecolor($width, $height);
	
	// Preserve transparency
	$transparent_index = imagecolortransparent($this-&gt;image);
	if ($transparent_index &gt;= 0) {	// GIF
		imagepalettecopy($this-&gt;image, $new_image);
		imagefill($new_image, 0, 0, $transparent_index);
		imagecolortransparent($new_image, $transparent_index);
		imagetruecolortopalette($new_image, true, 256);
	} 
	else	// PNG
	{
		imagealphablending($new_image, false);
		imagesavealpha($new_image,true);
		$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
		imagefilledrectangle($new_image, 0, 0, $width,$height, $transparent);
	}

	imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight());</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know if all problems are solved, but here are my changes based on the initial script, to make everything (PNG, GIF) work well:</p>
<p>$new_image = imagecreatetruecolor($width, $height);</p>
<p>	// Preserve transparency<br />
	$transparent_index = imagecolortransparent($this-&gt;image);<br />
	if ($transparent_index &gt;= 0) {	// GIF<br />
		imagepalettecopy($this-&gt;image, $new_image);<br />
		imagefill($new_image, 0, 0, $transparent_index);<br />
		imagecolortransparent($new_image, $transparent_index);<br />
		imagetruecolortopalette($new_image, true, 256);<br />
	}<br />
	else	// PNG<br />
	{<br />
		imagealphablending($new_image, false);<br />
		imagesavealpha($new_image,true);<br />
		$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);<br />
		imagefilledrectangle($new_image, 0, 0, $width,$height, $transparent);<br />
	}</p>
<p>	imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight());</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nkos</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-35023</link>
		<dc:creator>nkos</dc:creator>
		<pubDate>Thu, 02 Jun 2011 12:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-35023</guid>
		<description>Perfect !
Thank you !!

nico</description>
		<content:encoded><![CDATA[<p>Perfect !<br />
Thank you !!</p>
<p>nico</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jure Sah</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-34609</link>
		<dc:creator>Jure Sah</dc:creator>
		<pubDate>Thu, 21 Apr 2011 21:14:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-34609</guid>
		<description>Thanks. Used here: http://www.rockettheme.com/forum/index.php?f=214&amp;t=130087&amp;p=647850&amp;rb_v=viewtopic#p647850</description>
		<content:encoded><![CDATA[<p>Thanks. Used here: <a href="http://www.rockettheme.com/forum/index.php?f=214&#038;t=130087&#038;p=647850&#038;rb_v=viewtopic#p647850" rel="nofollow">http://www.rockettheme.com/forum/index.php?f=214&#038;t=130087&#038;p=647850&#038;rb_v=viewtopic#p647850</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bacc</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-34364</link>
		<dc:creator>bacc</dc:creator>
		<pubDate>Tue, 05 Apr 2011 01:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-34364</guid>
		<description>Excelent!! I found some errors in the script (resizeimage.php is imageresize.php)

The only code working on the network!

---

Excelente!! Encontre un par de errores en el script (resizeimage.php se llama imageresize.php)

El unico codigo que funciona en la red!!

Saludos!!!</description>
		<content:encoded><![CDATA[<p>Excelent!! I found some errors in the script (resizeimage.php is imageresize.php)</p>
<p>The only code working on the network!</p>
<p>&#8212;</p>
<p>Excelente!! Encontre un par de errores en el script (resizeimage.php se llama imageresize.php)</p>
<p>El unico codigo que funciona en la red!!</p>
<p>Saludos!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohamed El Allali</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-33187</link>
		<dc:creator>Mohamed El Allali</dc:creator>
		<pubDate>Mon, 21 Feb 2011 18:34:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-33187</guid>
		<description>Hello, nice script thanks for sharing, just a small error in the usage script

$image = &quot;some/dir/image.png&quot;; // File image location
 should be 
$img = &quot;some/dir/image.png&quot;; // File image location

i need it to keep the same ratio as the original image, i&#039;ll try to modify it later, but any suggestion is welcome ^_^</description>
		<content:encoded><![CDATA[<p>Hello, nice script thanks for sharing, just a small error in the usage script</p>
<p>$image = &#8220;some/dir/image.png&#8221;; // File image location<br />
 should be<br />
$img = &#8220;some/dir/image.png&#8221;; // File image location</p>
<p>i need it to keep the same ratio as the original image, i&#8217;ll try to modify it later, but any suggestion is welcome ^_^</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Saunderson</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-33004</link>
		<dc:creator>James Saunderson</dc:creator>
		<pubDate>Tue, 15 Feb 2011 12:39:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-33004</guid>
		<description>Thanks! that fixed it.

while trying to find the problem i noticed the actual image was transparent, the php created image was transparent then i resized imagecopyresampled() to be smaller than my full image and it is that function that is losing the transparency of the copied image:

[php]
$bgImageURL = &#039;blue-bg.gif&#039;;
$bgImage = imagecreatetruecolor(156,40);
imagealphablending($bgImage, false);//needed
//imagesavealpha($bgImage,true); //not needed
$transparent = imagecolorallocatealpha($bgImage, 255, 255, 255,127);//needed
//imagecolortransparent($bgImage,$transparent); //not needed
imagefilledrectangle($bgImage, 0, 0, 156, 40, $transparent);//needed
$srcimage = @imagecreatefromgif($bgImageURL);
imagecopyresized($bgImage, $srcimage, 0, 0, 0, 0, 146, 30, 1000, 250);
//imagecopyresampled($bgImage,$srcimage,0,0,0,0, 146,30,1000,250);//loses transparency
header(&#039;content-type: image/gif&#039;);
imagegif($bgImage);
[/php]

likely sounds like a bug in later versions
i am running PHP Version 5.2.6 &amp; GD Version:  bundled (2.0.34 compatible)</description>
		<content:encoded><![CDATA[<p>Thanks! that fixed it.</p>
<p>while trying to find the problem i noticed the actual image was transparent, the php created image was transparent then i resized imagecopyresampled() to be smaller than my full image and it is that function that is losing the transparency of the copied image:</p>
<p>[php]<br />
$bgImageURL = &#8216;blue-bg.gif&#8217;;<br />
$bgImage = imagecreatetruecolor(156,40);<br />
imagealphablending($bgImage, false);//needed<br />
//imagesavealpha($bgImage,true); //not needed<br />
$transparent = imagecolorallocatealpha($bgImage, 255, 255, 255,127);//needed<br />
//imagecolortransparent($bgImage,$transparent); //not needed<br />
imagefilledrectangle($bgImage, 0, 0, 156, 40, $transparent);//needed<br />
$srcimage = @imagecreatefromgif($bgImageURL);<br />
imagecopyresized($bgImage, $srcimage, 0, 0, 0, 0, 146, 30, 1000, 250);<br />
//imagecopyresampled($bgImage,$srcimage,0,0,0,0, 146,30,1000,250);//loses transparency<br />
header(&#8216;content-type: image/gif&#8217;);<br />
imagegif($bgImage);<br />
[/php]</p>
<p>likely sounds like a bug in later versions<br />
i am running PHP Version 5.2.6 &amp; GD Version:  bundled (2.0.34 compatible)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Navi</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-32883</link>
		<dc:creator>Navi</dc:creator>
		<pubDate>Thu, 10 Feb 2011 13:21:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-32883</guid>
		<description>Not working for transparent GIF&#039;s - PHP 5 / GD 2 / Linux</description>
		<content:encoded><![CDATA[<p>Not working for transparent GIF&#8217;s &#8211; PHP 5 / GD 2 / Linux</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Extract And Display A Re-sized Image From A WordPress Post In Archives And Searches &#124; Bharat Karavadra</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-32515</link>
		<dc:creator>Extract And Display A Re-sized Image From A WordPress Post In Archives And Searches &#124; Bharat Karavadra</dc:creator>
		<pubDate>Sat, 22 Jan 2011 14:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-32515</guid>
		<description>[...] You can extract and resize JPEG, GIF and PNG images from your posts. (PNG and GIF transparency is in development. PNG transparency on resize is working thanks to soem code by Miaz Mauzka). [...]</description>
		<content:encoded><![CDATA[<p>[...] You can extract and resize JPEG, GIF and PNG images from your posts. (PNG and GIF transparency is in development. PNG transparency on resize is working thanks to soem code by Miaz Mauzka). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bharat Karavadra</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-32514</link>
		<dc:creator>Bharat Karavadra</dc:creator>
		<pubDate>Sat, 22 Jan 2011 14:54:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-32514</guid>
		<description>Thank you Miaz,

I am creating an image resize feature for WordPress and I had ssiues with PNG&#039;s always having a balck background when resized.

I use a part of you code and resized PNG images now appear as they should. I have not yet tested it for GIF&#039;s but I&#039;m sure your code will work as it works for PNG&#039;s.

You can take a look a look at a WordPress post that has a transparent PNG here:
http://www.karavadra.net/wordpress/contact-form-for-wordpress
and if you finf this post in the arhcives or search results then you will see a resized transparent version.

Thank you again.</description>
		<content:encoded><![CDATA[<p>Thank you Miaz,</p>
<p>I am creating an image resize feature for WordPress and I had ssiues with PNG&#8217;s always having a balck background when resized.</p>
<p>I use a part of you code and resized PNG images now appear as they should. I have not yet tested it for GIF&#8217;s but I&#8217;m sure your code will work as it works for PNG&#8217;s.</p>
<p>You can take a look a look at a WordPress post that has a transparent PNG here:<br />
<a href="http://www.karavadra.net/wordpress/contact-form-for-wordpress" rel="nofollow">http://www.karavadra.net/wordpress/contact-form-for-wordpress</a><br />
and if you finf this post in the arhcives or search results then you will see a resized transparent version.</p>
<p>Thank you again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: banderon</title>
		<link>http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/comment-page-2/#comment-32278</link>
		<dc:creator>banderon</dc:creator>
		<pubDate>Wed, 12 Jan 2011 19:49:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=133#comment-32278</guid>
		<description>I tried this with no luck as well.  I could not use imagecopyresampled, and had to use the following instead:
imagecolortransparent($newImg, $transparent);
imagecopyresized($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);

This works for the transparency, but the image quality is poor (resize is worse than resample).  Any ideas why I can&#039;t use resample?</description>
		<content:encoded><![CDATA[<p>I tried this with no luck as well.  I could not use imagecopyresampled, and had to use the following instead:<br />
imagecolortransparent($newImg, $transparent);<br />
imagecopyresized($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);</p>
<p>This works for the transparency, but the image quality is poor (resize is worse than resample).  Any ideas why I can&#8217;t use resample?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

