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

[eluser]#1313[/eluser]
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?
#2

[eluser]nirbhab[/eluser]
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.
#3

[eluser]#1313[/eluser]
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.
#4

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

[eluser]#1313[/eluser]
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)
Code:
$dst_img = $create($this->width, $this->height);

2. insert these lines right after that line:
Code:
// 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.
#6

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

Thank you!
#7

[eluser]Tobz[/eluser]
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
#8

[eluser]Unknown[/eluser]
Using 1.70


Solved the problem inserting only these lines:

Code:
$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]

+1
#9

[eluser]vigna[/eluser]
Thank you very much #1313 for the code. It indeed worked.

Thank you so much...
#10

[eluser]BrianDHall[/eluser]
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