Создание анимированных GIF на PHP
Для создания анимированных GIF на PHP и GD можно использовать библиотеку GIFEncoder.class написанную László Zsidi.
Привожу небольшой пример как из двух кадров:
![]() |
![]() |
можно создать анимацию:

header ('Content-type:image/gif');
include('GIFEncoder.class.php');
$text = "Hello World";
// Open the first source image and add the text.
$image = imagecreatefrompng('source01.png');
$text_color = imagecolorallocate($image, 200, 200, 200);
imagestring($image, 5, 5, 5, $text, $text_color);
// Generate GIF from the $image
// We want to put the binary GIF data into an array to be used later,
// so we use the output buffer.
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$framed[]=40;
// Delay in the animation.
ob_end_clean();
// And again..
// Open the first source image and add the text.
$image = imagecreatefrompng('source02.png');
$text_color = imagecolorallocate($image, 200, 200, 200);
imagestring($image, 5, 20, 20, $text, $text_color);
// Generate GIF from the $image
// We want to put the binary GIF data into an array to be used later,
// so we use the output buffer.
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$framed[]=40;
// Delay in the animation.
ob_end_clean();
// Generate the animated gif and output to screen.
$gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');
echo $gif->GetAnimation();
Для сохранения анимации в файл достаточно удалить команду header(); в начале скрипта и вместо echo $gif->GetAnimation(); поместить:
$fp = fopen('animegif.gif', 'w');
fwrite($fp, $gif->GetAnimation());
fclose($fp);
Ссылки
- Создание gif-анимации с динамическими элементами на PHP+GDLib
- Howto: Generate animated GIF with PHP
- Class: GIF images into animated GIF with native PHP class


