Git Product home page Git Product logo

colibri.js's Introduction

Colibri.js (demo)

Colibri is a lightweight library allowing easy computation of colors based on an image. It allows this kind of thing :

Examples

Usage

var img = new Image( );
img.onload = function ( ) { alert( Colibri.extractImageColors( img, 'css' ) ); };
img.src = 'myImage.jpg';

Please note that it will not work if you try to load a remote image subject to cross-origin restrictions. However, if the target host is properly configured (and if you're not using IE), you should be able to do the following :

var img = new Image( );
img.onload = function ( ) { alert( Colibri.extractImageColors( img, 'css' ) ); };
img.crossOrigin = 'Anonymous';
img.src = 'http://i.imgur.com/OUmDIOqb.jpg';

Performances

You should be aware of performance issue on a large number of images on some devices such as iPad. I think it would be for the best if you could precompute the colors and store them somewhere. I plan to publish this library as a NPM package, don't forget to star the repo to be notified of further updates.


Use this script on little images (thumbnail-like). If necessary, you can resize the images yourself :

var img = new Image( );

img.onload = function ( ) {
    var canvas = document.createElement( 'canvas' );
    var context = canvas.getContext( '2d' );

    var maxWidth = 200, maxHeight = 200;
    var widthRatio = Math.max( 1, img.width / maxWidth );
    var heightRatio = Math.max( 1, img.height / maxHeight );
    var maxRatio = Math.max( widthRatio, heightRatio );

    canvas.width = img.width / maxRatio;
    canvas.height = img.height / maxRatio;

    context.drawImage( img, 0, 0, canvas.width, canvas.height );

    alert( Colibri.extractImageColors( canvas, 'css' ) );
};

img.crossOrigin = 'Anonymous';
img.src = 'http://i.imgur.com/OUmDIOq.jpg';

colibri.js's People

Contributors

arcanis avatar

Watchers

 avatar  avatar

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.