• Stars
    star
    808
  • Rank 56,429 (Top 2 %)
  • Language
    HTML
  • License
    ISC License
  • Created almost 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The simple, customizable, tiny javascript color extractor

npm version Join the chat at https://gitter.im/LukyVj/Colorify.js

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

    <script src="path/to/colorify.js"></script>
  </body>

And add the colorify.css to the head:

  <link rel="stylesheet" href="colorify.css">

Browserify setup

Just require colorify as any other CommonJS module after installing it via npm:

var colorify = require('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 :

colorify({});

Which is the equivalent to :

colorify({
  id: 1,
  attr: 'colorify',
  container: 'scene',
  images: false,
  accuracy: 100,
  gradient: false,
  gradientDirection: 'to bottom right',
  padding: 4,
  lazyReveal: {
    transition: 1, 
    delay: 1,
    steps: false
  },
  giveTo: false,
  revealOn: false
});

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

colorify({
  container: 'dynamic-images',
  images: [
    'path/to/image1.png',
    'path/to/image2.jpg',
    'path/to/image3.gif'
  ]
});

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

colorify({
  container: 'colorify-main-color',
  accuracy: 10
});

And for example you've got this markup

<div colorify-main-color>
  <img colorify src="image1.jpg">
  <img colorify src="image2.jpg">
  <img colorify src="image3.jpg">
</div>

It will result in :

<div colorify-main-color>
  <div class="image-container" style="padding: 4px; background-color: rgb(221, 89, 80);">
    <img colorify="" src="image1.jpg" class="colorify visible all-loaded" style="transition: all 1000ms ease 1000ms;">
  </div>
  <div class="image-container" style="padding: 4px; background-color: rgb(63, 147, 220);">
    <img colorify="" src="image2.jpg" class="colorify visible all-loaded" style="transition: all 1000ms ease 1000ms;">
    </div>
  <div class="image-container" style="padding: 4px; background-color: rgb(22, 196, 102);">
    <img colorify="" src="image3.jpg" class="colorify visible all-loaded" style="transition: all 1000ms ease 1000ms;">
  </div>
</div>

Get a gradient

To get a gradient from an image, you write the colorify script with the following parameters and values

colorify({
  container: 'colorify-gradient-color',
  accuracy: 10,
  gradient: true,
  gradientDirection: 'to bottom right'
});

With the following markup

<div colorify-gradient-color>
  <img colorify src="image1.jpg">
  <img colorify src="image2.jpg">
  <img colorify src="image3.jpg">
</div>

It will result in

<div colorify-gradient-color>
  <div class="image-container" style="padding: 4px; background-image: linear-gradient(to right bottom, rgb(233, 117, 104), rgb(224, 86, 77)); background-color: rgb(221, 89, 80);">
    <img src="image1.jpg" colorify="" class="colorify visible all-loaded" style="transition: all 1000ms ease 1000ms;">
  </div>
  <div class="image-container" style="padding: 4px; background-image: linear-gradient(to right bottom, rgb(61, 157, 220), rgb(75, 152, 222)); background-color: rgb(63, 147, 220);">
    <img src="image2.jpg" colorify="" class="colorify visible all-loaded" style="transition: all 1000ms ease 1000ms;">
  </div>
  <div class="image-container" style="padding: 4px; background-image: linear-gradient(to right bottom, rgb(29, 208, 118), rgb(22, 163, 75)); background-color: rgb(22, 196, 102);">
    <img src="image3.jpg" colorify="" class="colorify visible all-loaded" style="transition: all 1000ms ease 1000ms;">
  </div>
</div>

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

colorify({
  container: 'colorify-lazy-reveal',
  lazyReveal: {
    delay: 3 // 3 second before revealing
  }
});

All at once with transition

To reveal the images all at once but with a delay

colorify({
  container: 'colorify-lazy-reveal-2',
  lazyReveal: {
    transition: 2,  // The transition occurs for 2 seconds
    delay: 3
  }
});

All at once with a stepped transition

To reveal the images all at once but with a delay and stepped

colorify({
  container: 'colorify-lazy-reveal-3',
  lazyReveal: {
    transition: 2,  // The transition occurs for 2 seconds
    delay: 1,
    steps: true
  }
});

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 !

colorify({
  container: 'colorify-reveal-on-event',
  revealOn: {
    event: 'mouseOver',
    trigger: '#hover'
  }
});

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

colorify({
  container: 'colorify-reveal-on-event',
  give: {
    property: 'background',
    target: 'parent'
  }
});

Give it to children

colorify({
  container: 'colorify-reveal-on-event',
  give: {
    property: 'background',
    target: 'child'
  }
});

Give it to the exact element

colorify({
  container: 'colorify-reveal-on-event',
  give: {
    property: 'background',
    target: '.cover'
  }
});

API

Config

colorify({
  id: numeric,
  container: string,
  attr: string, 
  images: array,
  accuracy: numeric,
  color: boolean,
  gradient: boolean,
  gradientDirection: string,
  padding: numeric,
  lazyReveal: {
   transition: numeric, 
   delay: numeric,
   steps: boolean
  },
  give: {
    property: string,
    target: string
  },
  revealOn: {
    trigger: string
    event: string
  }
});

Example

colorify({
  id: 1,
  container: 'colorify-container',
  attr: 'colorify', 
  images: [
    'image1.png',
    'image2.jpg',
    'image3.gif'
  ],
  accuracy: 20,
  color: false,
  gradient: true,
  gradientDirection: 'to top left',
  padding: 10,
  lazyReveal: {
   transition: 1, 
   delay: 1,
   steps: true
  },
  give: {
    property: 'color',
    target: '.header h1'
  },
  revealOn: {
    trigger: '#start'
    event: 'click'
  }
});

default

colorify({
  id: 1,
  container: 'colorify',
  attr: 'colorify', 
  images: false,
  accuracy: 100,
  color: boolean,
  gradient: false,
  gradientDirection: false,
  padding: 4,
  lazyReveal: false,
  give: false,
  revealOn: false
});

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

Stargazers over time

Stargazers over time

Bitdeli Badge

More Repositories

1

family.scss

Family.scss is a set of Sass mixins which will help you to manage the style of :nth-child'ified elements, in an easy way.
SCSS
2,309
star
2

colofilter.css

Colofilter.css - Duotone filters made with CSS !
CSS
619
star
3

menu-to-cross-icon

One idea, 6 possibilities
CSS
183
star
4

accecss

AcceCSS A Sass Mixin That debug & check the accessibility of your designs
CSS
136
star
5

rainbow.js

A jQuery library to manage gadients easily !
CSS
60
star
6

gitShare

A Chrome extension to share github projects on Twitter & Facebook
JavaScript
28
star
7

fifty-shades-of

A 50 shades color picker :
CSS
24
star
8

Trinity-grid

Because we mostly don't need to have up to 12 columns
CSS
20
star
9

jarvis.js

Jarvis.js
JavaScript
19
star
10

EfficaCSS

A set of SASS & Bourbon mixins to power up your stylesheets And to provide you the best OVCSS system.
CSS
19
star
11

MadamNazar.io

A website to display Madam Nazar location
JavaScript
16
star
12

3DView.css

A clunky implementation of the aborted Firefox 3D view
CSS
13
star
13

dev-logos

13
star
14

animate.scss

Just a SASS Structure of Animate.css made by Daniel Eden : http://daneden.me/ ||
CSS
12
star
15

populus.js

Small javascript toolbelt to populate search inputs
CSS
12
star
16

rplace-algolia

r/place like playground recreated with Algolia
TypeScript
11
star
17

covfefe.css

covfefe
CSS
9
star
18

github_advanced_styles

A chrome extension to add advanced CSS styles to github
JavaScript
9
star
19

OVCSS

Organise Views CSS - Download the framework : http://lukyvj.github.io/OVCSS/ovcss-v1.0.1.zip Or go to the website :
CSS
9
star
20

cloudinary-blurhash

Generate a JSON file containing the blurhash of your cloudinary media library
JavaScript
8
star
21

LetMeTakeASelfie

Jocky website, first time with Gulp
CSS
8
star
22

blurhash-playground

blurhash-playground
TypeScript
6
star
23

instascii

An instafeed.js plugin that returns ASCII versions of images
JavaScript
6
star
24

minimalist-css-starter-kit

Its a style that you can directly upload to your pages/sites to display content in a minimalistic way.
6
star
25

Plugr.js

A simple JavaScript function that helps you to manage your web plugins.
CSS
5
star
26

lucasbonomi.com-v2

Second version of my website
CSS
5
star
27

ios-meta

5
star
28

identifi.js

identifi.js is an open project, which aims to make the people identification easier on pictures. View it on github Β»
CSS
5
star
29

snippets.js

A collection of useful javascript code snippets.
4
star
30

CSSMS

CSSMS : A CMS Full of CSS !
CSS
4
star
31

debug-tools.css

a collection of debugging CSS tools.
CSS
4
star
32

SpreadR

A collaborative project of @dervondenbergen, @jofpin & I. More infos soon.
CSS
4
star
33

HexaTime.js

A jQuery plugin to create colored Text, backgrounds, borders ect, with a color based on the time ! (if 22:30:40, color #223040 )
CSS
4
star
34

dribbble-to-codepen

To help you doing your Dribbble to Codepen thing
CSS
4
star
35

just-code

The most simple online code editor.
CSS
4
star
36

flippets

A collection of flat ui snippets
3
star
37

rdr2-naturalist-almanac

Data for the naturalist.guide data and Harriet Discord bot.
3
star
38

WAPSS

WAPSS
JavaScript
3
star
39

nunc

nunc - Online comunication made easy
CSS
3
star
40

easUI

A simple & lovely CSS framework
3
star
41

randomiCSSer

Generate random CSS values on the fly
TypeScript
3
star
42

algolia-wallpapers

CSS
3
star
43

try_git

3
star
44

awesomenews

Landing page awesome news
PHP
3
star
45

I.B.A

Images to Base64 to ASCII - Node, Jade, JSCII
CSS
3
star
46

important.js

Make your life easier for testing developement pages.
JavaScript
3
star
47

focuzin

Generate a rectangle over any images format to focus on a particular zone of the image
JavaScript
3
star
48

lucasbonomi.com

My website
JavaScript
3
star
49

ap-moji

APMOJI Random Users API, made with emojis
JavaScript
2
star
50

algolia-ph

Algolia's product hunted
CSS
2
star
51

JeSuisCharlie

An hommage to the victims of Charlie Hebdo the 7 of January 2015
JavaScript
2
star
52

SKIDIP

Team Skidip website
JavaScript
2
star
53

focucss

Focus your users, on your sidebar.
CSS
2
star
54

horizonMap

WIP
2
star
55

hire.lucasbonomi.com

Hire me >
CSS
2
star
56

frontend_console

A friendly debugging console for frontend developers
CSS
2
star
57

VertiGrid

CSS
2
star
58

B2Oipsum

Un gΓ©nΓ©rateur de lorem ipsum un peu plus thug
JavaScript
2
star
59

blendmode-filter-video

Small app created for my talk at CSS Paris Meetup (http://www.meetup.com/fr/CSS-Paris)
JavaScript
2
star
60

website

My website page
HTML
2
star
61

sassets-pipeline

CSS
2
star
62

shorthand.it

A free online service to get the shorthand css of a property
JavaScript
2
star
63

one-step

Wait for it.
2
star
64

MTO

MTO Weather web application - Live app on :
JavaScript
2
star
65

naturalist.guide

TODO
TypeScript
2
star
66

jqDebug.js

jqDebug.js is a tiny jquery function that will helps you to debug your projects.
JavaScript
2
star
67

upvote.it

PHP
2
star
68

Introduction-to-Gulp.js

Demo repository for https://medium.com/@lukyvj/an-introduction-to-gulp-js-295ee489e2c9 Demo :
JavaScript
2
star
69

lukyvj.design

JavaScript
2
star
70

fortnite-maps

images files
1
star
71

exchange

Exchange is a repository created to be used as a public personal chatroom on Gitter.
1
star
72

html-colors-extended

A SASS file that expand the HTML color names
CSS
1
star
73

blendr

JavaScript
1
star
74

YO-COOL-URL

A small app to send URL via the YO network.
CSS
1
star
75

doiv-tpircavaj.js

133 Octets of awesomeness - Abraham Lincoln
CSS
1
star
76

AweCSSome-Newsletter

1
star
77

Fontizer

https://github.com/LukyVj/fontizer-site
JavaScript
1
star
78

CSS-methodology

My own CSS guidelines & methods
1
star
79

codesearch

instantsearch implementation with codepen data
CSS
1
star
80

lucasbonomi.com-blog

test
1
star
81

chitchat

1
star
82

ProJSTechniques

An index of JS techniques & Experiments
CSS
1
star
83

landing

http://lukyvj.github.io/landing/
CSS
1
star
84

CaCSScade

The best OVCSS managing system
CSS
1
star
85

is-bricks

WIP
CSS
1
star
86

longshade-flat-icon-maker

Longshade Flat Icon Maker
JavaScript
1
star
87

LinkR

turn any expression which contains .com into a link with jquery
CSS
1
star
88

Design

Get all design element
1
star
89

init.css

The perfect style for your project or reading pages
1
star
90

Bulltax

CSS
1
star
91

BullCSSMS

CSS
1
star
92

varfile

A javascript variables organizer system
JavaScript
1
star
93

viz-ir

vis-reg-test
JavaScript
1
star
94

polyfaces

Website to show and sell polygon faces designs
CSS
1
star
95

cssnippets

1
star
96

lukyshawty

Use of SPOTWIFY
TypeScript
1
star
97

lukyvj.github.io

1
star
98

frontenders

If you like front and tenders πŸ—
JavaScript
1
star
99

bulltaxt

The bullgit code color syntaxt
1
star
100

img_overlay

A tiny Jquery tool that helps you to re-create items in css
JavaScript
1
star