CodeIgniter Forums
Image lib black background on crop - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Image lib black background on crop (/showthread.php?tid=27069)



Image lib black background on crop - El Forum - 01-31-2010

[eluser]zbrox[/eluser]
Hi there,

I'm trying to resize an image to a smaller one with different proportions. The resulting image comes out with an area of black where's the extra space. However I need it to be either transparent, or white, but not black Smile
I edited the Image library so that it would resize PNG's without losing the transparency. I added this:
Code:
if ($this->image_type == 3 || $this->image_type == 1) {
             //Using alpha channel
             imagealphablending($dst_img, false);
             imagesavealpha($dst_img,true);
             //Allocating transparent color
             $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
             //full image filled with transparent color
             imagefilledrectangle($dst_img, 0, 0, $this->width,  $this->height, $transparent);
           }

Judging by it imagefilledrectangle gets $transparent as a background color, I tried changing it to the $white variable used above in the code, but still the result is a black background.
Any ideas why this is happening?


Image lib black background on crop - El Forum - 01-31-2010

[eluser]matt2012[/eluser]
Have you set your library to GD2?


Image lib black background on crop - El Forum - 01-31-2010

[eluser]zbrox[/eluser]
Yes, I'm using GD2, not GD.


Image lib black background on crop - El Forum - 01-31-2010

[eluser]zbrox[/eluser]
I forgot to mention I'm using Codeigniter 1.7.2.


Image lib black background on crop - El Forum - 04-24-2010

[eluser]elvix[/eluser]
i'm not sure you need that last line imagefilledrectangle. try deleting it?