All Projects → stil → Gif Endec

stil / Gif Endec

PHP GIF encoder and decoder

Labels

Projects that are alternatives of or similar to Gif Endec

Asciicast2gif
Generate GIF animations from asciicasts (asciinema recordings)
Stars: ✭ 874 (+1287.3%)
Mutual labels:  gif
Gif rain code
生成gif数字雨动态头像
Stars: ✭ 40 (-36.51%)
Mutual labels:  gif
Movtogif Cli
📺 Convert mov/mp4 to high-quality animated gifs
Stars: ✭ 56 (-11.11%)
Mutual labels:  gif
Llgifview
轻量级gif加载,可加载本地和网络的gif图片
Stars: ✭ 20 (-68.25%)
Mutual labels:  gif
Gifmagic
💈 Gif maker and extractor in Swift
Stars: ✭ 38 (-39.68%)
Mutual labels:  gif
Format parser
file metadata parsing, done cheap
Stars: ✭ 46 (-26.98%)
Mutual labels:  gif
Giflossy
Merged into Gifsicle!
Stars: ✭ 937 (+1387.3%)
Mutual labels:  gif
Gifimageview
Android ImageView that handles animated GIF images
Stars: ✭ 1,126 (+1687.3%)
Mutual labels:  gif
Gifloader
An Android Library to load your GIF files
Stars: ✭ 38 (-39.68%)
Mutual labels:  gif
Mojito
微信、bilibili大图、长图、gif、视频、自定义view的转场效果,The transition effect of wechat, bilibili large image, long image, GIF, video and custom view
Stars: ✭ 1,068 (+1595.24%)
Mutual labels:  gif
Glide
An image loading and caching library for Android focused on smooth scrolling
Stars: ✭ 32,046 (+50766.67%)
Mutual labels:  gif
Peek
Peek makes it easy to create short screencasts of a screen area. It was built for the specific use case of recording screen areas, e.g. for easily showing UI features of your own apps or for showing a bug in bug reports. With Peek, you simply place the Peek window over the area you want to record and press "Record". Peek is optimized for generating animated GIFs, but you can also directly record to WebM or MP4 if you prefer.
Stars: ✭ 8,408 (+13246.03%)
Mutual labels:  gif
Gifsee.js
A modern, vanilla JavaScript gif previewer and loader.
Stars: ✭ 48 (-23.81%)
Mutual labels:  gif
Pm2.5 Idw Map
PM2.5 IDW Map from PM2.5 open data portal
Stars: ✭ 14 (-77.78%)
Mutual labels:  gif
Qrcode
💮 amazing QRCode generator in Python (supporting animated gif) - Python amazing 二维码生成器(支持 gif 动态图片二维码)
Stars: ✭ 8,613 (+13571.43%)
Mutual labels:  gif
Sdwebimageswiftui
SwiftUI Image loading and Animation framework powered by SDWebImage
Stars: ✭ 844 (+1239.68%)
Mutual labels:  gif
Aimage
An animated gif & apng engine for iOS in Swift. Have a great performance on memory and cpu usage.
Stars: ✭ 1,014 (+1509.52%)
Mutual labels:  gif
Gifline
The fast way to put gif in or emails
Stars: ✭ 63 (+0%)
Mutual labels:  gif
Gifmaker
Android 平台下合成 GIF,使用多线程优化的版本,20张/12s
Stars: ✭ 62 (-1.59%)
Mutual labels:  gif
Ar Gif
Easy to use augmented reality web components
Stars: ✭ 52 (-17.46%)
Mutual labels:  gif

Introduction

What is that?

gif-endec is a GIF encoder and decoder. It allows you to split animated GIFs into separate frames. You can also extract frame durations and disposal method (disposal method indicates the way in which the graphic is to be treated after being displayed).

Performance

Thanks to some code optimizations, this library decodes animated GIFs much faster than Sybio/GifFrameExtractor. It also optimizes memory usage, allowing you to process decoded frames one after another. It doesn't load all frames to memory at once.

Installation

Install this package with Composer.

composer require stil/gif-endec

Split animated GIF into frames

In this example we'll split this animated GIF into separate frames.

<?php
require __DIR__ . '/../vendor/autoload.php';

use GIFEndec\Events\FrameDecodedEvent;
use GIFEndec\IO\FileStream;
use GIFEndec\Decoder;

/**
 * Open GIF as FileStream
 */
$gifStream = new FileStream("path/to/animation.gif");

/**
 * Create Decoder instance from MemoryStream
 */
$gifDecoder = new Decoder($gifStream);

/**
 * Run decoder. Pass callback function to process decoded Frames when they're ready.
 */
$gifDecoder->decode(function (FrameDecodedEvent $event) {
    /**
     * Convert frame index to zero-padded strings (001, 002, 003)
     */
    $paddedIndex = str_pad($event->frameIndex, 3, '0', STR_PAD_LEFT);

    /**
     * Write frame images to directory
     */
    $event->decodedFrame->getStream()->copyContentsToFile(
        __DIR__ . "/frames/frame{$paddedIndex}.gif"
    );
    // Or get binary data as string:
    // $frame->getStream()->getContents()

    /**
     * You can access frame duration using Frame::getDuration() method, ex.:
     */
    echo $event->decodedFrame->getDuration() . "\n";
});

The result frames will be written to directory:

Render animated GIFs' frames

If your GIF is saved using transparency, some frames might look like this:

In following example you'll see how to render GIF frames.

<?php
require __DIR__ . '/../vendor/autoload.php';

use GIFEndec\Events\FrameRenderedEvent;
use GIFEndec\IO\FileStream;
use GIFEndec\Decoder;
use GIFEndec\Renderer;

/**
 * Open GIF as FileStream
 */
$gifStream = new FileStream("path/to/animation.gif");

/**
 * Create Decoder instance from MemoryStream
 */
$gifDecoder = new Decoder($gifStream);

/**
 * Create Renderer instance
 */
$gifRenderer = new Renderer($gifDecoder);

/**
 * Run decoder. Pass callback function to process decoded Frames when they're ready.
 */
$gifRenderer->start(function (FrameRenderedEvent $event) {
    /**
     * $gdResource is a GD image resource. See http://php.net/manual/en/book.image.php
     */

    /**
     * Write frame images to directory
     */
    imagepng($event->renderedFrame, __DIR__ . "/frames/frame{$event->frameIndex}.png");
});

Create an animation

Assume now, that we want to slow down this skateboarder animation a little bit, so we can see how to make such trick. We already have splitted frames in skateboarder/frame*.gif directory.

<?php
use GIFEndec\Color;
use GIFEndec\Encoder;
use GIFEndec\Frame;
use GIFEndec\IO\FileStream;

$gif = new Encoder();

foreach (glob('skateboarder/frame*.gif') as $file) {
    $stream = new FileStream($file);
    $frame = new Frame();
    $frame->setDisposalMethod(1);
    $frame->setStream($stream);
    $frame->setDuration(30); // 0.30s
    $frame->setTransparentColor(new Color(255, 255, 255));
    $gif->addFrame($frame);
}

$gif->addFooter(); // Required after you're done with adding frames

// Copy result animation to file
$gif->getStream()->copyContentsToFile('skateboarder/animation.gif');

This is how our slowed down animation would look like:

Disposal methods explained

Disposal Method indicates the way in which the graphic is to be treated after being displayed.

Values :    0 -   No disposal specified. The decoder is
                  not required to take any action.
            1 -   Do not dispose. The graphic is to be left
                  in place.
            2 -   Restore to background color. The area used by the
                  graphic must be restored to the background color.
            3 -   Restore to previous. The decoder is required to
                  restore the area overwritten by the graphic with
                  what was there prior to rendering the graphic.
         4-7 -    To be defined.

Source: http://www.w3.org/Graphics/GIF/spec-gif89a.txt

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].