2017 © Pedro PelĂĄez
 

library anim-gif

PHP class to create an animated GIF from multiple images

image

lunakid/anim-gif

PHP class to create an animated GIF from multiple images

  • Thursday, December 7, 2017
  • by afrowuk
  • Repository
  • 8 Watchers
  • 51 Stars
  • 13,533 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 91 Forks
  • 2 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

NOTE: This is a fork of Clément Guillemain's nice GifCreator class, with some API changes (class rename, new & updated methods, more flexible (and robust) parameter handling etc.), better error handling, several small corrections, code cosmetics & other improvements scattered all across., (*1)

About

AnimGif is a PHP class to create animated GIFs -- just list the source images (in various forms), and that's it!, (*2)

Usage

1. Inputs:, (*3)

// Use an array containing file paths, resource vars (initialized with imagecreatefromXXX), 
// image URLs or binary image data.
$frames = array(
    imagecreatefrompng("/../images/pic1.png"),      // resource var
    "/../images/pic2.png",                          // image file path
    file_get_contents("/../images/pic3.jpg"),       // image binary data
    "http://thisisafakedomain.com/images/pic4.jpg", // URL
);

// Or: load images from a dir (sorted, skipping .files):
//$frames = "../images";

// Optionally: set different durations (in 1/100s units) for each frame
$durations = array(20, 30, 10, 10);

// Or: you can leave off repeated values from the end:
//$durations = array(20, 30, 10); // use 10 for the rest
// Or: use 'null' anywhere to re-apply the previous delay:
//$durations = array(250, null, null, 500);

2. Create the GIF:, (*4)

``` php $anim = new GifCreator\AnimGif(); $anim->create($frames, $durations);, (*5)

// Or: using the default 100ms even delay: //$anim->create($frames);, (*6)

// Or: loop 5 times, then stop: //$anim->create($frames, $durations, 5); // default: infinite looping, (*7)


**3. Get/use the result:** You can now get the animated GIF binary: ```php $gif = $anim->get();

...and e.g. send it directly to the browser:, (*8)

header("Content-type: image/gif");
echo $gif;
exit;

Or just save it to a file:, (*9)

$anim->save("animated.gif");

Behavior

  • Transparency is based on the first frame. [!!NOT VERIFIED: "It will be saved only if you give multiple frames with the same transparent background"]
  • The dimensions of the generated GIF are based on the first frame, too. If you need to resize your images to get the same dimensions, you can use this class: https://github.com/Sybio/ImageWorkshop.

Dependencies

  • PHP 5.3 (for namespace support & whatnot; noone still shamelessly uses PHP < 5.3, right?!)
  • GD (imagecreatefromstring, imagegif, imagecolortransparent)

Credits

The Versions

07/12 2017

dev-master

9999999-dev https://github.com/lunakid/AnimGif

PHP class to create an animated GIF from multiple images

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php gif encode creation animated

24/05 2014

1.3

1.3.0.0 https://github.com/lunakid/AnimGif

PHP class to create an animated GIF from multiple images

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php gif encode creation animated

17/05 2014

1.2

1.2.0.0 https://github.com/lunakid/AnimGif

PHP class to create an animated GIF from multiple images

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php gif encode creation animated

25/04 2014

1.1

1.1.0.0 https://github.com/lunakid/AnimGif

PHP class to create an animated GIF from multiple images

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php gif encode creation animated

13/10 2012

1.0.0

1.0.0.0 https://github.com/Sybio/GifCreator

PHP class that creates animated GIF from multiple images

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php gif encode creation animated