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



Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.