CodeIgniter Forums

Full Version: image_lib - resizing transparent png24
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]mandelkern[/eluser]
Hi,

I tried to resize a png-24 file with the codeigniter-image_lib, using GD2. The result looses its transparency and shows a black background.

I couldn't find any solutions, fixing this within the image_lib.

Can someone help me with this problem?


Thanks.

El Forum

[eluser]Référencement Google[/eluser]
Look at:
http://ellislab.com/forums/viewthread/62955/#311374

Is this helping?

El Forum

[eluser]mandelkern[/eluser]
Thanks, elite but I already tried this. It helps fine with gif and png-8 but my problem seems to be special with GD2 and png-24.

El Forum

[eluser]Référencement Google[/eluser]
I posted the issue some time ago:
http://ellislab.com/forums/viewthread/71962/

It is a CI bug and it looks like nobody has found a solution yet. You'll have to dive into the CI Image lib code and rework the GD part that make the transparency working. Sorry I can't help much more.

El Forum

[eluser]mandelkern[/eluser]
Ok. Thanks anyway. I'll try my best :-)

El Forum

[eluser]Référencement Google[/eluser]
If you find a solution please post it.

El Forum

[eluser]BorisK[/eluser]
I had this same problem solved in PHP a while ago. Can you send me a link to a sample image that fails to work. If it keeps transparency in my code I'll port the hack to CI library.

El Forum

[eluser]mandelkern[/eluser]
I found a solution at http://www.webdeveloper.com/forum/showthread.php?t=178210.

Nearly at line

514 - $dst_img = $create($this->width, $this->height);

I changed the code this way:

//$dst_img = $create($this->width, $this->height);

/* TRANSPARENT PNG */
$dst_img = imagecreatetruecolor($this->width, $this->height);
$transparent = imagecolorallocatealpha($dst_img,0,255,0,127);
imagefill($dst_img,0,0,$transparent);

$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);

imageAlphaBlending($dst_img, false);
imageSaveAlpha($dst_img, true);

..and now it works.

El Forum

[eluser]Référencement Google[/eluser]
Hey that's really cool, please report that + solution to the bug tracker of CI or to the forums bugs category

El Forum

[eluser]BorisK[/eluser]
That's pretty similar to my PHP code, except that I refactored the ImageSetAlpha function:
Code:
function ResizeImage($newWidth, $newHeight)
    {
        $this->newWidth = $newWidth;
        $this->newHeight = $newHeight;
        $this->dest_image = imagecreatetruecolor($this->newWidth, $this->newHeight);
        $this->ImageSetAlpha();
        imagecopyresampled($this->dest_image, $this->src_image, 0, 0, 0, 0,
          $this->newWidth, $this->newHeight, imagesx($this->src_image), imagesy($this->src_image));
        $this->src_image = $this->dest_image;
    }

    function ImageSetAlpha ()
    {
        $background = imagecolorallocate($this->dest_image, 0, 0, 0);
        ImageColorTransparent($this->dest_image, $background);
        imagealphablending($this->dest_image, false);
    }
Pages: 1 2