Jump to content

Overlay some text on an animated gif using GD?


gausie

Recommended Posts

Hi there!

 

I've got a couple of gifs that I'd like to randomly pick. I got that sorted with this:

 

<?php

$classes = array ("AT", "DB", "PM", "SC", "SR", "TT");

header("Content-Type: image/gif");
@readfile("./" . $classes[rand(0,5)] . ".gif") or die("File not found.");

?>

 

However, it is now appropriate to overlay some text on each gif. So I tried this:

 

<?php

$classes = array ("AT", "DB", "PM", "SC", "SR", "TT");

$string = "Random Picture";
$chosen = "./" . $classes[rand(0,5)] . ".gif";
$im = imagecreatefromgif($chosen);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 0, 0, $string, $black);
imagegif($im);
imagedestroy($im);

?>


  •  
    But that's just giving me a text version of my GIF:
     
GIF87a<�d����������������������HHH&&&���,,,�.....
 
So my problems here are
 
  • Problem displaying the image
  • I don't even know if it's working to overlay on every frame of the animation, since it wont display

 

gausie



I just tried with one of my animated gifs

 

It overlays the text but loses the animation

 

(you forgot the content-type header, btw)

 

<?php
$string = 'ABC';
$chosen = "connection.gif";
$im = imagecreatefromgif($chosen);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 0, 0, $string, $black);
header("content-type: image/gif");
imagegif($im);
imagedestroy($im);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.