diff_image 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

diff_image #

A Dart Package to get the % difference between two images of the same width and height.

diff_image is a Dart version of this with changes on visualization and , you guessed it, the language.

Example #

A simple usage example:

import 'package:diff_image/diff_image.dart';

final FIRST_IMAGE = 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-cs.png';
final SECOND_IMAGE = 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-node.png';

void foo() async{
  try{
      var diff = await DiffImage.compareFromUrl(FIRST_IMAGE, SECOND_IMAGE);
      print('The difference between images is: $diff %');
  } catch(e){
      print(e);
  }
}

main() {
  foo();
}

A more detailed example can be found here

Features #

  1. Currently there is support only for images from the web (urls)
  2. The compareFromUrl definition is:
     static Future<num> compareFromUrl(
           firstImgSrc, secondImgSrc,
           {ignoreAlpha=true, asPercentage=true, saveDiff=false}
           ) async{...}

where:

  • ignoreAlpha allows to decide whether to take alpha from RGBA into account for the calculation
  • asPercentage set the format of the output (as percentage or between 0-1)
  • saveDiff save a png showing the differences between [firstImgSrc] and [secondImgSrc] (currently not available on Dart Web)

Sample Results #

First Image #

flutter_logo

Second Image #

android_logo

Difference Percentage #

With Alpha : 35.67169421487167 %

Without Alpha : 34.83905183744361 %

Difference Image #

DiffImg

Suggestions and bugs #

Please file feature requests, suggestions and bugs at the issue tracker.

0.1.1 #

  • Fixed some health suggestions from Dart Pub

0.1.0 #

  • Initial version, created by Limonadev.
  • Support for comparing only images from web (urls)

example/diff_image_example.dart

import 'package:diff_image/diff_image.dart';

final FIRST_IMAGE = 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-cs.png';
final SECOND_IMAGE = 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-node.png';

main() async{

  //You need a try/catch block to handle the exceptions (http request, different size, etc)
  try{
    //You can decide whether to take [alpha] into account for the calculation of the difference
    //Also you can decide the format of the output: As percentage or between 0 and 1
    var diff = await DiffImage.compareFromUrl(FIRST_IMAGE, SECOND_IMAGE, ignoreAlpha: false, asPercentage: false);
    print('The difference between images is: $diff');

    diff = await DiffImage.compareFromUrl(FIRST_IMAGE, SECOND_IMAGE, ignoreAlpha: false);
    print('The difference between images is: $diff percent');

    diff = await DiffImage.compareFromUrl(FIRST_IMAGE, SECOND_IMAGE);
    print('The difference between images is: $diff percent');


    //Only run this if you are not on Dart Web (saveDiff not supported yet on Dart Web)
    //saveDiff allows you to save a png showing the differences between the two images
    //diff = await DiffImage.compareFromUrl(FIRST_IMAGE, SECOND_IMAGE, ignoreAlpha: false, saveDiff: true);
    //print('The difference between images is: $diff percent');
  } catch(e){
    print(e);
  }

}

Use this package as a library

1. Depend on it

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


dependencies:
  diff_image: ^0.1.1

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:diff_image/diff_image.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/diff_image.dart.

Run dartfmt to format lib/diff_image.dart.

Format lib/src/diff_image_html.dart.

Run dartfmt to format lib/src/diff_image_html.dart.

Format lib/src/diff_image_io.dart.

Run dartfmt to format lib/src/diff_image_io.dart.

Format lib/src/helper_functions.dart.

Run dartfmt to format lib/src/helper_functions.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
http ^0.12.0+3 0.12.0+4
image ^2.1.10 2.1.12
Transitive dependencies
archive 2.0.13
args 1.6.0
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
http_parser 3.1.4
meta 1.1.8
path 1.6.4
petitparser 3.0.2
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
xml 3.7.0 4.1.0
Dev dependencies
pedantic ^1.8.0 1.9.0
test ^1.6.0