PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How do edit animated GIF image with GD?

 October 11, 2022     gd, image-processing, php     No comments   

Issue

I use this function to update an animated GIF image, but GD is rendering it as static?

function draw_image ()

  {

    $img=imagecreatefromgif('images/moni.gif');

    $text='test';
    $lastpayout='test'; 
    $colors['name'] = imagecolorallocate($img, 999, 000, 156);
    ImageTTFText($img, 9, 0, 20, 235, $colors['name'], "images/impact.ttf", $text);
    ImageTTFText($img, 9, 0, 20, 250, $colors['name'],"images/tahoma.ttf",$lastpayout);
    ImageTTFText($img, 10, 0, 15, 270, $colors['name'], "images/tahoma.ttf", $text);
    header("Content-type: image/gif");
    imagegif($img);
  }

echo  draw_image ();

This function converts the animated GIF into a static GIF. Can anyone help me?


Solution

If you can use imagick:

$gif = new Imagick('full/path/to/your/image.gif');

$draw = new ImagickDraw();    
$draw->setFont('full/path/to/your/font.ttf');
$draw->setFontSize(30);
$draw->setFillColor('white');

// put text on each frame
foreach($gif as $frame){
  $gif->annotateImage($draw, $x = 10, $y = 45, $angle = 0, 'Your text');         
}    

header('Content-Type: image/gif');
print $gif->getImagesBlob();


Answered By - nice ass
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing