The simple, customizable, tiny javascript color extractor.
Showcase
We'd love to see what you're creating with colorify.js ! If you want to send your creations, and get featured on http://colorify.rocks and on the github repo, send the url in a comment on the issue Community Showcase !
Be creative !
In summary, with Colorify.js, you can :
- Extract the dominant color from an image
- Generate gradients based on the images colors
- Isolate colors and manipulates them everywhere in the page
- Create a Lazy-revealer system for your images
- Load image dynamically
- Create any
colorify({});
instances you want
The script works with ANY images format : png, jpeg, jpg, gif
Installation
With npm
npm install colorify.js
With bower
bower install colorifyjs
Regular Setup
To install colorify, just download the script and load it at the end of your page
And add the colorify.css to the head:
Browserify setup
Just require colorify as any other CommonJS module after installing it via npm:
var colorify = ;
In terms of CSS you have to decide whether you reference the CSS file as described above or use a tool like parcelify to bundle the CSS.
Basic config
Keep in mind that you have to host the images on your server in order to avoid CORS restrictions
If your page contains only one section where you want to use colorify, you can use the basic config, to do so, you just need to load colorify like this :
;
Which is the equivalent to :
;
Load image dynamically
Sometimes you don't want to bother yourself writing too much code, you may want to load your images dynamically, there is a param for this in colorify.js, the images: parameter, you can pass an array of images to add them on your selected container
;
Get main color
The main value of colorify is the ability to extract the average color of an image, to do so, call the function like this
;
And for example you've got this markup
It will result in :
Get a gradient
To get a gradient from an image, you write the colorify script with the following parameters and values
;
With the following markup
It will result in
Lazy reveal
This is an interesting aspect of Colorify, and kindof the reason of it's existence. It will allow you to Lazy-reveal your images.
We use the term Lazy-reveal because it's not "lazy-loading" them per say. Because Colorify is a 100% client script, the only way colorify can process your images is when they are loaded and so, when they are loaded, the script hide them directly, process them and reveal them.
You can set the time you want, and it will reveal each images based on this time.
All at once without transition
To reveal the images all at once without any transition but a delay
;
All at once with transition
To reveal the images all at once but with a delay
;
All at once with a stepped transition
To reveal the images all at once but with a delay and stepped
;
Display on event
You may want to display the image when a certain element is clicked ? from the body to an ID, you can display the images on any event, with any trigger !
;
Manipulates color
This is a cool aspect of Colorify, you can extract the color from a picture, and give it's value to any element on the page
The property parameter accepts :
- background / background-color
- color
- outline-color
- border-color
- fill
- box-shadow
Give it to the parent
;
Give it to children
;
Give it to the exact element
;
API
Config
;
Example
;
default
;
Parameters
- id : The id of the colorify instance
- container : The class or id of the container
- attr : The attribute to use on the images to process, by default, the attribute is the same value as container
- images : Pass an array to it if you need to dynamically add images
- accuracy : Each visited pixels, the more high the value is, faster the rendering will be.
- color : Set to true if you want colorify to give you the main color of the image, by default the value is true
- gradient : Set to true if you want colorify to return a gradient instead of a color, by default the value is false
- gradientDirection : If the gradient value is set to true, use this parameter to define de gradient direction
- padding : If you want to have padding around your images and fake a colored border effect, give it a value or false, by default the value is 4
- lazyReveal :
- transition: Set the time a transition should length, by default, the value is 0
- delay: Define the time before the animation should start, by default, the value is 0
- steps: Set to true if you want the images to reveal one after an other, by default the value is false
- give :
- property: Define wich property should use the image extracted color, by default the value is false
- target: Give the selector class, id, name or attribute that should use the color with the defined property
- revealOn :
- trigger: The selector class, id, name or attribute that should trigger the reveal, by default the value is false
- event: The event to use to make the animation occur, of course the event will be attached to the trigger