PHP Classes

Add Text to Animation Frame?

Recommend this page to a friend!

      GIF images into animated GIF with native PHP class  >  All threads  >  Add Text to Animation Frame?  >  (Un) Subscribe thread alerts  
Subject:Add Text to Animation Frame?
Summary:How can I add Text to Animation Frame?
Messages:6
Author:dunny
Date:2008-09-11 15:21:50
Update:2009-02-08 15:44:36
 

  1. Add Text to Animation Frame?   Reply   Report abuse  
Picture of dunny dunny - 2008-09-11 15:21:50
$im[0] = 'images/GCHTML/GamerCard_main.gif';
$im[1] = 'images/GCHTML/GamerCard_bd.gif';

$color = imagecolorallocate($im, 255, 255, 255);
$font = 'Fonts/verdana.ttf';
$text = "MY TEXT HERE";

imagettftext($im[0], 16, 0, 60, 44, $color, $font, $text);

$gif = new GIFEncoder (
$im,
5,
0,
2,
0, 0, 0,
"url"
);

header("Content-type: image/gif");
echo $GIF->GetAnimation ( );

----------------------------------------------------------------


Hi, love your work, I feel I'm close to achieving what I need.

I can animate the two images ($im) but I'm unable to add text to the first image ($im[0]).

Can anyone help?

Thanks.

  2. Re: Add Text to Animation Frame?   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2008-09-24 21:20:46 - In reply to message 1 from dunny
Your code is ok., but not complete!
I thought that you want write watermark into the frames on the fly...
I will be to complement your sourcecode that you can use it to make watermark on the fly.

$font = 'Fonts/verdana.ttf';
$text = "MY TEXT HERE";

for $i=0; $i < $frames; $i++ ) {
$pointer = imagecreatefromgif ( 'images/GCHTML/xxx_$i.gif' );
$color = imagecolorallocate($pointer , 255, 255, 255);
imagettftext($pointer , 16, 0, 60, 44, $color, $font, $text);
ob_start();
$im[] = ob_get_contents();
ob_end_clean();
imagedestroy($pointer);
}

$gif = new GIFEncoder (
$im,
5,
0,
2,
0, 0, 0,
"bin"
);

header("Content-type: image/gif");
echo $GIF->GetAnimation ( );

  3. Re: Add Text to Animation Frame?   Reply   Report abuse  
Picture of SteveThomas SteveThomas - 2009-02-08 13:26:51 - In reply to message 1 from dunny
Hello,

I couldn't get either of these examples posted working. So I tried a simpler one.


for ($i=1; $i < 3; $i++ ) {
$pointer = imagecreatefromgif ( "images/images0$i.gif" );
ob_start();
$frames[$i] = ob_get_contents();
$framed [$i] = 10;
ob_end_clean();
imagedestroy($pointer);

And I get this error:

Warning: fread(): supplied argument is not a valid stream resource in directory/GIFEncoder.class.php on line 65
GIFEncoder V2.05: 0 Source is not a GIF image!

Now the files are gifs because they work with the example code included. But I wanted to try and figure out how to add text. I thought the first step would be to try and load the images into ob_get_contents first. Once I could get that working, I could add text.

Any thoughts what I am doing wrong in that code?

Whoops Sorry for the double post

  4. Re: Add Text to Animation Frame?   Reply   Report abuse  
Picture of SteveThomas SteveThomas - 2009-02-08 13:30:12 - In reply to message 1 from dunny
Hello,

I couldn't get either of these examples posted working. So I tried a simpler one.


for ($i=1; $i < 3; $i++ ) {
$pointer = imagecreatefromgif ( "images/images0$i.gif" );
ob_start();
$frames[$i] = ob_get_contents();
$framed [$i] = 10;
ob_end_clean();
imagedestroy($pointer);

And I get this error:

Warning: fread(): supplied argument is not a valid stream resource in directory/GIFEncoder.class.php on line 65
GIFEncoder V2.05: 0 Source is not a GIF image!

Now the files are gifs because they work with the example code included. But I wanted to try and figure out how to add text. I thought the first step would be to try and load the images into ob_get_contents first. Once I could get that working, I could add text.

Any thoughts what I am doing wrong in that code?

Whoops Sorry for the double post

  5. Re: Add Text to Animation Frame?   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2009-02-08 15:41:45 - In reply to message 3 from SteveThomas
Hi,

ob_get_contents ( ) function can not give nothing from an empty buffer.
You MUST use the imageGif, imageJpeg or imagePNG function between ob_start and ob_end_clean functions!

So, your code in this manner correct:

for ($i=1; $i < 3; $i++ ) {
$pointer = imagecreatefromgif ( "images/images0$i.gif" );
ob_start();
// DON'T FORGET
imageGif ( $pointer );
//
$frames[$i] = ob_get_contents();
$framed [$i] = 10;
ob_end_clean();
imagedestroy($pointer);

  6. Re: Add Text to Animation Frame?   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2009-02-08 15:44:36 - In reply to message 2 from László Zsidi
Unfortunately that i forget the imageGif ( ) function in my example.
I am so sorry...