Welcome Guest, Not a member yet? Register   Sign In
image_lib - resizing transparent png24
#1

[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.
#2

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

Is this helping?
#3

[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.
#4

[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.
#5

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

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

[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.
#8

[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.
#9

[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
#10

[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);
    }




Theme © iAndrew 2016 - Forum software by © MyBB