colorgram 1.0.0 copy "colorgram: ^1.0.0" to clipboard
colorgram: ^1.0.0 copied to clipboard

Colorgram is a lightweight tool that allows you to extract prominent colors from image. This is a Dart port of the original Colorgram.js library.

Features #

This library allows you to extract colors from an image, which can be used to determine the colors of Flutter widgets or output into a CSV. This is a port of the Colorgram JS library by darosh on GitHub.

It uses the Relative Luminance, Hue, and Lightness values to sample to colors.

Compared to other color extraction packages in Dart, this package is lightweight, fast and simple to use, removing all the bloat and only providing you with only what you need. Additionally, it also supports usage in pure Dart projects.

Showcase Image

Supports:

JPG
PNG / Animated APNG
GIF / Animated GIF
BMP
TIFF
TGA
PVR
ICO
WebP / Animated WebP
PSD
EXR

(bascially any file that the Image library supports read operations for)

Benchmarks: (Desktop)

  • 512x512 JPEG in ~ 100ms
  • 5120x1440 JPEG in ~1000ms

Getting started #

Please ensure your image is converted into a File object from the File class in dart:io

  1. If you have a file path, simply wrap it in a File function
final file = File('PATH TO YOUR IMAGE');
  1. If you have a XFile type (used in image_picker & more)
final rawXFile;
final file = File(rawXFile.path);

Usage #

This package only requires you to interact with one simple method, the extractColor(), which takes in a File object and an integer representing the number of color outputs the user wants

final file = File('PATH TO YOUR IMAGE');
List<CgColor> colorList =extractColor(file, 10);

The results will be outputted in a list of CgColor objects, in order of most prominent

CgColor(int r, int g, int b, num percentage)

You can then use this in your widgets using Flutter's Color object

Color.fromARGB(255, CgColor.r, CgColor.g, CgColor.b)

NOTE: The function does not take into account Alpha values, all outputs are considered to be fully opaque. Thus, the Alpha/Opacity values for the Color widgets should have a value of 255/1 respectively for accurate color representation.

Passing a list of Images -> File/XFile type

List<List<CgColor>> finalData = imageList.map((e) => extractColor(File(e.path), 10)).toList();

Additional information #

Please note that a significant portion of the program's execution time is spent converting the Image File to UINT8 bytes. If feasible, directly passing the byte data will cut the runtime in half.

Do contribute to the project if you find a faster alternative

Credits: darosh on Github for the original Colorgram library

6
likes
0
points
100
downloads

Publisher

unverified uploader

Weekly Downloads

Colorgram is a lightweight tool that allows you to extract prominent colors from image. This is a Dart port of the original Colorgram.js library.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

image

More

Packages that depend on colorgram