CodeIgniter Forums
Resizing of transparent/animated gifs [solved] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Resizing of transparent/animated gifs [solved] (/thread-3693.html)

Pages: 1 2


Resizing of transparent/animated gifs [solved] - El Forum - 10-17-2007

[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?


Resizing of transparent/animated gifs [solved] - El Forum - 10-17-2007

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


Resizing of transparent/animated gifs [solved] - El Forum - 10-17-2007

[eluser]#1313[/eluser]
Well, yes, there are some techniques, like http://forums.devshed.com/php-development-5/gd-image-resize-transparent-gif-337812.html, but my question was actually about the working implementation on CI.


Resizing of transparent/animated gifs [solved] - El Forum - 10-17-2007

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


Resizing of transparent/animated gifs [solved] - El Forum - 10-23-2007

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


Resizing of transparent/animated gifs [solved] - El Forum - 11-15-2007

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

Thank you!


Resizing of transparent/animated gifs [solved] - El Forum - 04-07-2008

[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


Resizing of transparent/animated gifs [solved] - El Forum - 08-23-2009

[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


Resizing of transparent/animated gifs [solved] - El Forum - 09-15-2009

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

Thank you so much...


Resizing of transparent/animated gifs [solved] - El Forum - 09-15-2009

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