gif_dart 1.0.0

Dart GIF encoder. A library for Dart developers. This library wrap gif.js(https://github.com/jnordberg/gif.js).

Usage #

You must include the right gif.js JavaScript libraries into your .html file to be able to use this package. Usually this means including gif.js gif.worker.js. https://github.com/jnordberg/gif.js

  <script type="text/javascript" src="gif.js"></script>
  <script type="text/javascript" src="gif.worker.js"></script>

A simple usage example:

import 'package:gif_dart/gif_dart.dart';

main() {
  final canvas = CanvasElement();
  var gif = GIF(Options(workers: 10, quality: 10));
  gif.addFrame(canvas, AddFrameOptions(copy: true));
  gif.addFrame(canvas, AddFrameOptions(copy: true));
  gif.on('finished', allowInterop((blob, tmp) {
    window.open(Url.createObjectUrl(blob), 'gif');
  }));
  gif.render();
  querySelector('#output').text = 'Your Dart app is running.';
}

To use dart2js instead of dartdevc, add the --release flag:

$  webdev serve --release  # uses dart2js

To run this web app with web worker correctly in the browser during development, instead of the common webdev serve, we need to use webdev serve -r. Which indicate a release version, in other word, use dart2js instead of dartdevc. This hinder debugging by lot.

Caution #

  gif.on('finished', allowInterop((blob, tmp) {
    window.open(Url.createObjectUrl(blob), 'gif');
  }));
  gif.render();

Difference in JS interop callback behaviour between DDC and dart2js(https://github.com/dart-lang/sdk/issues/33134)

  gif.on 'finished', (blob, data) ->
    if blobURLSupport
      renderimg.src = URL.createObjectURL(blob)
    else
      renderimg.src = buildDataURL(data)
    delta = now() - startTime
    logel.set 'text', "Rendered #{ images.length } frame(s) at q#{ gif.options.quality } in #{ delta.toFixed(2) }ms"

https://github.com/jnordberg/gif.js/blob/a2201f123ed9e5582e57c3d15f5df00c0b8367bd/site/contents/scripts/main.coffee#L50-L56 gif.on('finish') need two argument.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

MIT

1.0.0 #

  • Initial version, created by Stagehand

example/gif_dart_example.dart

import 'dart:html';
import 'dart:js';

import 'package:gif_dart/gif_dart.dart';

main() {
  final canvas = CanvasElement();
  var gif = GIF(Options(workers: 10, quality: 10));
  gif.addFrame(canvas, AddFrameOptions(copy: true));
  gif.addFrame(canvas, AddFrameOptions(copy: true));
  gif.on('finished', allowInterop((blob, tmp) {
    window.open(Url.createObjectUrl(blob), 'gif');
  }));
  gif.render();
  querySelector('#output').text = 'Your Dart app is running.';
}

Use this package as a library

1. Depend on it

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


dependencies:
  gif_dart: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:gif_dart/gif_dart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
92
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Maintenance suggestions

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
js ^0.6.0 0.6.1+1
path ^1.6.0 1.6.4
Dev dependencies
pedantic ^1.8.0
test ^1.6.0