Git Product home page Git Product logo

iris-lib's Introduction

iris-lib

build crates.io

Generate color palettes from pixels or images using the mediancut algorithm.

example_output_image

Usage

Include iris-lib in your Cargo.toml:

iris-lib = "0.1.0"

Create palettes from pixels:

use iris_lib::color_bucket::ColorBucket;
use iris_lib::color::Color;

fn main() {
    let colors = vec![
        Color { r: 255, g: 0, b: 0, a: 0 },
        Color { r: 0, g: 255, b: 0, a: 0 },
        Color { r: 0, g: 0, b: 255, a: 0 }
    ];

    if let Some(mut bucket) = ColorBucket::from_pixels(colors) {
        let palette = bucket.make_palette(3); // three iterations
        println!("{:?}", palette);
    };
}

Result:

[Color { r: 255, g: 0, b: 0, a: 0 }, 
 Color { r: 0, g: 255, b: 0, a: 0 }, 
 Color { r: 0, g: 0, b: 255, a: 0 }]

Images

Include the image feature in your Cargo.toml reference.

iris-lib = { version = "0.1.0", features = ["image"]}

Create palettes by passing the path of the target image:

use iris_lib::color_bucket::ColorBucket;

fn main() {
    if let Some(mut bucket) = ColorBucket::from_image("peppers.png") {
        let palette = bucket.make_palette(2); // two iterations
        println!("{:?}", palette);
    };
}

Result:

[Color { r: 165, g: 197, b: 124, a: 255 }, 
 Color { r: 144, g: 172, b: 74, a: 255 }, 
 Color { r: 192, g: 51, b: 42, a: 255 }, 
 Color { r: 97, g: 42, b: 25, a: 255 }]

Command line tool

Check out iris the command line tool built on top of this library.

iris-lib's People

Contributors

kaesebrot84 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

master-of-zen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.