Welcome Guest, Not a member yet? Register   Sign In
Resizing of transparent/animated gifs [solved]

Hi there, people.

Did anybody here encounter any problems with CI imagelib when working (i.e. resizing) with animated gifs or gifs with transparency? In my case the resulting image gets slightly messed up -- all of transparent areas are black.

I know that this is not CI's fault, but a general problem with native PHP functions such as imagecopyresampled(), which discard transparency and every frame but first one of the animated gif. My question is, actually, did anyone here already solved this on CI's grounds? Some magick patches to the core applied, maybe?

I too have same problem, please somebody answer. #1313 if i am correct says right that its core PHP problem, but there must be some solutions to these type of high end image manipulation.

Well, yes, there are some techniques, like http://forums.devshed.com/php-developmen...37812.html, but my question was actually about the working implementation on CI.

[eluser]Derek Allard[/eluser]
Try changing the image lib library. GD2 is better then GD, and Imagemagik might be better still (I don't know). There's also NetPBM if you have access to it.

There are no native functions capable of resizing transparent gifs in GD2.

So i wrote a little patch to the image_lib image_process_gd() function (actually, this patch is copied from PHP Online Manual):

0. backup your \system\libraries\Image_lib.php
1. locate following line of code in the \system\libraries\Image_lib.php (somewhere in the image_process_gd() function, near line #512)
$dst_img = $create($this->width, $this->height);

2. insert these lines right after that line:
// keeping transparency
        $transparent_index = imagecolortransparent($src_img);
        if ($transparent_index >= 0) {
            imagepalettecopy($src_img, $dst_img);
            imagefill($dst_img, 0, 0, $transparent_index);
            imagecolortransparent($dst_img, $transparent_index);
            imagetruecolortopalette($dst_img, true, 256);

3. test and see if this helped

In my case this patch completely did the magic and now my transparent gifs (and pngs) remain transparent after resizing. Hope this'll help someone.

[eluser]Fabian Wesner[/eluser]
@ #1313

Thank you!

Hi There,

just wondering if Derecks patch made it into CI 1.6.1?
I'm not getting transparency after resizing png's (using 1.6.1)

may I should just go and look Wink

Using 1.70

Solved the problem inserting only these lines:

$transparent_index = imagecolortransparent($src_img);

imagepalettecopy($src_img, $dst_img);
imagefill($dst_img, 0, 0, $transparent_index);
imagecolortransparent($dst_img, $transparent_index);
imagetruecolortopalette($dst_img, true, 256);

[quote author="Fabian Wesner" date="1195145835"]@ #1313

Thank you![/quote]


Thank you very much #1313 for the code. It indeed worked.

Thank you so much...

Great code, much appreciated. Was wondering what the hell was wrong with some of my images but not others.

Theme © iAndrew 2016 - Forum software by © MyBB