gifencoder 0.2.3

A gif encoder written in Dart.


To create a regular GIF:

import 'dart:html';
import 'package:gifencoder/gifencoder.dart';

int width = ...;
int height = ...;
var ctx = new CanvasElement(width: width, height: height).context2D;
// draw your image in the canvas context
var data = ctx.getImageData(0, 0, width, height);
List<int> bytes = gifencoder.makeGif(width, height,

To create an animated Gif, use a GifBuffer instead:

int framesPerSecond = ...;
var frames = new gifencoder.GifBuffer(width, height);
for (var i = 0; i < myFrameCount; i++) {
  // draw the next frame on the canvas context
  frames.add(ctx.getImageData(0, 0, width, height).data);
List<int> bytes =;

Once you have the bytes of the GIF, you can save it somewhere or convert it into a data URL. See example/squares.dart for how to do that.

1. Depend on it

Add this to your package's pubspec.yaml file:

  gifencoder: "^0.2.3"

2. Install it

You can install packages from the command line:

$ pub get

Alternatively, your editor might support 'pub get'. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:gifencoder/gifencoder.dart';


A library for creating gif files, including animated gifs.


Email Brian Slesinsky



Source code (hyperlinked)



Jul 28, 2013