PHP Classes

Transparency bug

Recommend this page to a friend!

      GIF images into animated GIF with native PHP class  >  All threads  >  Transparency bug  >  (Un) Subscribe thread alerts  
Subject:Transparency bug
Summary:transparency clause doesn't work in some cases
Messages:9
Author:Joram Nowak
Date:2006-08-02 17:32:32
Update:2006-10-04 15:00:07
 

  1. Transparency bug   Reply   Report abuse  
Picture of Joram Nowak Joram Nowak - 2006-08-02 17:32:32
Hi

first of all, great job, I can really use this on my website. I'm playing around with the class and learning how to use it right now, and I have stumbled on a minor problem: in your main code, you say:

if($t1 && $t2 && $t3)
{
$this->trans1 = $t1;
$this->trans2 = $t2;
$this->trans3 = $t3;
$this->transparent = true;
}

You see the problem here? What if I want 0,0,0 (black) to be my transparent color? This statement will never pass through this way. My image use the color 255,0,255 (magenta) for transparency and I couldn't understand why the transparency didn't work until I realized this. So basically if any of your $t1, $t2, or $t3 values is 0, it will not work.

So I changed it to: if($t1 > -1 && $t2 > -1 && $t3 > -1)

this has fixed the problem but I'm sure there's a better way.

Anyway, other than that, perfect little program my friend. You saved me a lot of headaches!

-Joram "ZweiFuss" Nowak
www.zweifuss.com

  2. Re: Transparency bug   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2006-08-26 14:44:47 - In reply to message 1 from Joram Nowak
Hi Joram,

Thank you very much your congratulations and feedback!
Your idea is good, afraid forgotten the possibility of the black transparent color.
I update the main code by your modification.

Regards

  3. Re: Transparency bug   Reply   Report abuse  
Picture of Khuc Nam Hai Khuc Nam Hai - 2006-09-02 05:57:49 - In reply to message 2 from László Zsidi
A great job,


I am using split and merge classes but meet a problem:
Split class is OK. mean I will have frames of original gif file.

But when I use merge class to merge frames together. It does not work with some gifs file (with combine format). The first frame has full of size, the following just has changed pixel. Other pixels are transparent. But when I merge them together. The transparent pixels changed to white color and the last gif file is incorrect format even I set for transparent color is white. How can I fix?

An other question: how can I write some text in frames when I merging?

Thanks

  4. Re: Transparency bug   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2006-09-03 07:35:35 - In reply to message 3 from Khuc Nam Hai
Hi,

Sorry, but your problem cannot be solved because the merge class use a global color table flag when combine frames.
If the first frame some color has been definied as white this color will be reserved in the global color table flag and cannot be modified if even the next colors of frames are different at this entry of global color table flag.
Single solution try to change colors in the local color table of single frames (I mean transparent color into not transparent color) before merge process.

If you want to draw some text into single frames before merge you can!

<?php
$im = array('image0.gif', 'image0.gif', 'image0.gif'); // Original frames
$fn = 'Arial.ttf';
$fs = 22;
$Tx = 'Test string';
for($frame = 0; $frame < count($im); $frame++)
{
$li = imageCreateFromGif($im[$frame]);
$co = imageColorAllocate($li, 127, 0, 0);
imageTTFText($li, $fs, 0, 20, 20, $co, $fn, $Tx);
ob_start();
imageGif($li);
imageGif($li);
$ti = ob_get_contents();
$combine[$frame] = $ti;
$delay[$frame] = 10;
ob_end_clean();
imageDestroy($li);
}
$anim = new GifMerge($combine, 0, 0, 0, -10, $delay, 2, 0, 0, 'C_MEMEORY');
?>

Regards,
László Zsidi

  5. Re: Transparency bug   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2006-09-03 07:38:18 - In reply to message 4 from László Zsidi
Correct, i mean '$im = array('image0.gif', 'image0.gif', 'image0.gif'); // Original frames
' -> $im = array('image0.gif', 'image1.gif', 'image2.gif'); // Original frames)

  6. Re: Transparency bug   Reply   Report abuse  
Picture of Khuc Nam Hai Khuc Nam Hai - 2006-09-03 17:39:28 - In reply to message 5 from László Zsidi
Hello László Zsidi,

Thanks so much for your help and great job

Nam


  7. Re: Transparency bug   Reply   Report abuse  
Picture of Satria / Ox41464b Satria / Ox41464b - 2006-10-04 07:27:20 - In reply to message 3 from Khuc Nam Hai
Here is my solutions for WaterMark

<?php
header('Content-type: image/gif');
require('GifMerge.class.php');
$i = array("http://files.phpclasses.org/graphics/elephpant_logo.gif",
"frame02.gif","frame03.gif","frame04.gif","frame05.gif",
"frame06.gif","frame07.gif","frame08.gif","frame09.gif",
"frame10.gif","frame11.gif","frame12.gif","frame13.gif",
"frame14.gif","frame15.gif","frame16.gif","frame17.gif");
$d = array(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);
$x = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$y = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$anim = new GifMerge($i, 0, 0, 0, 0, $d, $x, $y, 'C_FILE');


//Since disposal value unchangeable i re-loop,
//and re-prepare alll needed value
$anim->disposal = 0; //(GifMerge default is 2)
//0 = no action, 1 = no dispose,
//2 = restore background (default) 3 = restore previous


//ask GifMerge to re-Process
$anim->first=true;
$anim->fout='';
for($tmp_i = 0; $tmp_i < count($i); $tmp_i++)
{
$d[$tmp_i] ? $anim->delay = $d[$tmp_i] : $anim->delay = $anim->dly;
$x[$tmp_i] ? $anim->x = $x[$tmp_i] : $anim->x = 0;
$y[$tmp_i] ? $anim->y = $y[$tmp_i] : $anim->y = 0;
$anim->start_gifmerge_process($i[$tmp_i]);
}


echo $anim->getAnimation();

//result:
//We seing phpclass Logo as WaterMark (behind simpsons)

//Request: please submit patch for $disposal
?>

  8. Re: Transparency bug   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2006-10-04 14:15:42 - In reply to message 7 from Satria / Ox41464b
Hi,

Thank your reply and your modification it is really good job!

  9. Re: Transparency bug   Reply   Report abuse  
Picture of Satria / Ox41464b Satria / Ox41464b - 2006-10-04 15:00:07 - In reply to message 8 from László Zsidi
i guess "Thanks" should goes to you :D

now i can Merge 5 Animated.GIF into One.GIF
(with hard way of course)

currently i GifSplit all AnimatedImage into:
$container[$animationIndex][$frame];

and merge each $frame through GD
and ask GifMerge to Created Animated.GIF

works! but... buggy (specially disposal things)
and disposal is a must for me or GIF filesize Increase 2~3x

Im looking forward for your next release for this "multi image merge" feature

Thanks,
Satria / Ox41464b