color_thief_flutter 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

color_thief_flutter #

the Flutter implementation of color-thief, based on quantize_dart.

Usage #

import 'package:color_thief_flutter/color_thief_flutter.dart';
import 'package:color_thief_flutter/utils.dart';

// color_thief_flutter.dart

getColorFromUrl('url/to/image').then((color) {
  print(color); // [R,G,B]
});

getPaletteFromUrl('url/to/image').then((palette) {
  print(palette); // [[R,G,B]]
});

getImageFromUrl('url/to/image').then((image) {
  print(image); // Image
});

getImageFromProvider(imageProvider).then((image) {
  print(image); // Image
});

getColorFromImage(image).then((color) {
  print(color); // [R,G,B]
});

getPaletteFromImage(image).then((palette) {
  print(palette); // [[R,G,B]]
});

// utils.dart

final hsv = fromRGBtoHSV([90, 90, 90]);
print(hsv); // [0, 0, 35]

final rgb = fromHSVtoRGB([90, 90, 90]);
print(rgb); // [126, 230, 23]

color_thief_flutter.dart #

Main package of color_thief_flutter.

All these functions return null if the parameter is unqualified

getColorFromUrl(String url, [int quality])

returns the base color from the largest cluster, represented as [R,G,B]

getPaletteFromUrl(String url, [int colorCount, int quality])

returns a list that contains the reduced color palette, represented as [[R,G,B]]

getImageFromUrl(String url)

returns the Image from url

getImageFromProvider(ImageProvider imageProvider)

returns the real Image of ImageProvider

getColorFromImage(Image image, [int quality = 10])

returns the base color from the largest cluster, represented as [R,G,B]

getPaletteFromImage(Image image, [int colorCount, int quality])

returns a list that contains the reduced color palette, represented as [[R,G,B]]

parameters

  • url - Url to image.
  • imageProvider - ImageProvider.
  • image - Image that get from getImageFromProvider.
  • colorCount - Between 2 and 256. The maximum number of colours allowed in the reduced palette.
  • quality - Between 1 and 10. There is a trade-off between quality and speed. The bigger the number, the faster the palette generation but the greater the likelihood that colors will be missed.

utils.dart #

Tools for format colors.

May cause loss of significance

fromRGBtoHSV(List

retruns HSVColor, represented as [H,S,V]

fromHSVtoRGB(List

retruns RGBColor, represented as [R,G,B]

parameters

  • R,G,B's range is [0,255]
  • H's range is [0,360]
  • S,V's range is [0,100]

License #

Licensed under the MIT License.

1.0.0 #

Initialize publish.

1.0.1 #

Update doc and quantize_dart.

1.0.2 #

Update quantize_dart.

example/main.dart

import 'package:color_thief_flutter/color_thief_flutter.dart';
import 'package:color_thief_flutter/utils.dart';
import 'package:flutter/painting.dart';

void main() {

  // color_thief_flutter.dart

  final url = 'https://github.githubassets.com/images/modules/open_graph/github-octocat.png';
  final imageProvider = NetworkImage(url);

  getColorFromUrl(url).then((color) {
    print(color); // [R,G,B]
  });

  getPaletteFromUrl(url).then((palette) {
    print(palette); // [[R,G,B]]
  });

  getImageFromUrl(url).then((image) {
    print(image); // Image
  });

  getImageFromProvider(imageProvider).then((image) {
    print(image); // Image

    getColorFromImage(image).then((color) {
      print(color); // [R,G,B]
    });

    getPaletteFromImage(image).then((palette) {
      print(palette); // [[R,G,B]]
    });
  });

  // utils.dart

  final hsv = fromRGBtoHSV([90, 90, 90]);
  print(hsv); // [H,S,V]

  final rgb = fromHSVtoRGB([90, 90, 90]);
  print(rgb); // [R,B,G]

}

Use this package as a library

1. Depend on it

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


dependencies:
  color_thief_flutter: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:color_thief_flutter/color_thief_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
79
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]
90
Learn more about scoring.

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health suggestions

Format lib/color_thief_flutter.dart.

Run flutter format to format lib/color_thief_flutter.dart.

Format lib/utils.dart.

Run flutter format to format lib/utils.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
quantize_dart ^1.0.3 1.0.3
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test