GifCreator is a PHP class that creates animated GIF from multiple images

Related tags

Imagery GifCreator
Overview

================================

GifCreator

================================

GifCreator is a PHP class to create animated GIF from multiple images

For what ?

This class helps you to create an animated GIF image: give multiple images and their duration and that's it !

Usage

1 - Creation:

// Create an array containing file paths, resource var (initialized with imagecreatefromXXX), 
// image URLs or even binary code from image files.
// All sorted in order to appear.
$frames = array(
    imagecreatefrompng("/../images/pic1.png"), // Resource var
    "/../images/pic2.png", // Image file path
    file_get_contents("/../images/pic3.jpg"), // Binary source code
    'http://thisisafakedomain.com/images/pic4.jpg', // URL
);

// Create an array containing the duration (in millisecond) of each frames (in order too)
$durations = array(40, 80, 40, 20);

// Initialize and create the GIF !
$gc = new GifCreator();
$gc->create($frames, $durations, 5);

The 3rd parameter of create() method allows you to choose the number of loop of your animated gif before it stops. In the previous example, I chose 5 loops. Set 0 (zero) to get an infinite loop.

2 - Get the result:

You can now get the animated GIF binary:

$gifBinary = $gc->getGif();

Then you can show it in the navigator:

header('Content-type: image/gif');
header('Content-Disposition: filename="butterfly.gif"');
echo $gifBinary;
exit;

Or save it in a folder as a GIF:

file_put_contents('/myfolder/animated_picture.gif', $gifBinary);

Behavior

  • The transparency is based on the first given frame. It will be saved only if you give multiple frames with same transparent background.
  • The dimensions of the generated GIF are based on the first frame. If you need to resize your frames to get the same dimension, you can use this class: https://github.com/Sybio/ImageWorkshop

About

The class reuses some part of code of "GIFEncoder.class.php" by László Zsidi (thanks to him).

Comments
  • Problems with transparent gif

    Problems with transparent gif

    HI,

    I found that after create any gif with transparence the new gif in transparent part has black layers moving. @Sybio did you see this problem before? Could you solve this? Thank you!

    Regards

    opened by dpcat237 2
  • Create composer version

    Create composer version

    Hi

    Can you create a tagged stable version number in git please so that I can use your library in composer without setting the minimum-stability flag to dev?

    Thanks ;)

    opened by lboynton 2
  • init $this->frameSources array in create method

    init $this->frameSources array in create method

    This little change gives ability to chain method calls in my project which is using your great library without need of recreation the GifCreator Object.

    opened by glukash 1
  • Deprecated: Array and string offset access syntax with curly braces is deprecated in GifCreator.php

    Deprecated: Array and string offset access syntax with curly braces is deprecated in GifCreator.php

    Deprecated: Array and string offset access syntax with curly braces is deprecated in GifCreator.php on line 135.

    Using PHP 7.4.2

    Error can be fixed by replacing { 10 } with [10] in the code at several lines;

    opened by JanValkenburg 0
  • Too much Memory Required

    Too much Memory Required

    Dont work if pass paths? work only with imagecreatefrom()...

    find better way

    $GIF = new Imagick();
    $GIF->setFormat("gif");
    
     for ($i = 0; $i < sizeof($gifFrames); ++$i) {
                $frame = new Imagick();
                $frame->readImage($gifFrames[$i]);
                $frame->setImageDelay(100);
                $GIF->addImage($frame);
            }
    

    Imagick === No memory leak

    opened by evtuhovdo 0
  • Gif is too large

    Gif is too large

    I have tested much times making gif from 11 jpg/jpeg images,the result is too large over 450kb. Does GifCreator has some options or method to compress gif file? Thanks a lot!

    opened by nicecp 0
  • Unable to create Gif (even though it's been working fine in many other similar occasions)

    Unable to create Gif (even though it's been working fine in many other similar occasions)

    Warning: imagecreatefromstring(): gd-png: fatal libpng error: Read Error: truncated data in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113

    Warning: imagecreatefromstring(): gd-png error: setjmp returns error condition in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113

    Warning: imagecreatefromstring(): Passed data is not in 'PNG' format in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113

    Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113

    Fatal error: Uncaught exception 'Exception' with message 'GifCreator: Under development: 171 Source is not a GIF image.' in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php:132 Stack trace: #0 /Users/Flo/GitHub/whiteboard-comics/test.php(23): GifCreator\GifCreator->create(Array, Array, 0) #1 {main} thrown in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 132

    opened by Sheraff 1
  • Compression artifacts on Windows

    Compression artifacts on Windows

    GifCreator is working great on Mac/Linux, however when using it on a Windows machine, the output has some heavy compression artifacts, more visible dithering, banding and color shifts between frames for example.

    Mac output: mac

    Windows output: windows

    Any idea how this is caused?

    opened by eddial 0
Owner
Clément Guillemain
Clément Guillemain
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

Piotr Śliwa 879 Dec 30, 2022
The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API

Gregwar's Image class The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API. Installation With compos

Grégoire Passault 958 Dec 29, 2022
A PHP GD + TwitterOAuth demo to dynamically generate Twitter header images and upload them via the API.

A PHP GD + TwitterOAuth demo to dynamically generate Twitter header images and upload them via the API. This enables you to build cool little tricks, like showing your latest followers or sponsors, latest content creted, a qrcode to something, a progress bar for some goal, and whathever you can think of.

Erika Heidi 172 Jan 5, 2023
PHP library to resize, scale and crop images.

PHP library to resize, scale and crop images.

Gumlet 1.1k Jan 3, 2023
Inline Images Protocol implementation for PHP.

Imgecho Echo the image on iTerm App using Inline Images Protocol. Installation Use Composer to install. composer require mileschou/imgecho Usage Use

MilesChou 4 May 30, 2022
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library

================================ ImageWorkshop class ================================ Summary and features Really flexible and easy-to-use PHP class t

Clément Guillemain 853 Dec 27, 2022
Create images with embedded text using advanced typography

Image with Text This class makes it super easy to render images with multiple, independently styled text blocks. You can control each text block's ali

New Media Campaigns 144 Sep 7, 2022
Easily convert images with Glide

Easily convert images with Glide This package provides an easy to use class to manipulate images. Under the hood it leverages Glide to perform the man

Spatie 374 Dec 30, 2022
Optimize your images on the fly with Glide for Laravel.

Glide for Laravel Optimize your images on the fly with Glide for Laravel. Support us Like our work? You can support us by purchasing one of our produc

Flowframe 53 Oct 17, 2022
Upload SVG images in Magento 2.x

Upload SVG images in Magento 2.x This extension for Magento 2 allows uploading SVG images in the following sections: wysiwyg editor in static blocks a

Magegadgets 6 Dec 23, 2022
The Tinify API allows you to compress and optimize WebP, JPEG and PNG images.

The Tinify API allows you to compress and optimize WebP, JPEG and PNG images. It is designed as a REST service. The client libraries in various languages make it very easy to interact with the Tinify API.

Devscast 10 May 13, 2022
Simple, fast and secure archive for images

Slim Image Archive Simple*, fast and secure archive for images: Create multiple categories with multiple albums with multiple images! Manage multiple

KS 24 Oct 23, 2021
The image server plugin allows you to add responsive images via config without extra elements

Grav image server plugin adds picture tag with loading, responsive, high density images

catchIT 7 Dec 30, 2022
Create beautiful generative background images from a string. Based on jasonlong/geo_pattern

GeoPattern This is a PHP port of jasonlong/geo_pattern. Generate beautiful tiling SVG patterns from a string. The string is converted into a SHA and a

Redeye Group 106 Aug 17, 2022
Contao extension to provide the possibility of defining alternative images to be used on different output devices.

Contao Image Alternatives This extensions expands the capabilities of using responsive images with art direction in Contao. You will have the possibil

inspiredminds 6 May 30, 2022
Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file, move it to a new directory, and returns the new source for the image.

NO LONGER MAINTAINED!!! Image Cache v. 1.0.0 Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file,

Erik Nielsen 455 Dec 30, 2022
This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

null 59 Oct 5, 2022
PHP Exif Library - library for reading and writing Exif headers in JPEG and TIFF files using PHP.

PEL: PHP Exif Library README file for PEL: PHP Exif Library. A library with support for reading and writing Exif headers in JPEG and TIFF images using

null 264 Dec 4, 2022
PHP Image Manipulation

Intervention Image Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and com

null 13k Jan 3, 2023