npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

color-change

v1.1.4

Published

设置图片颜色, 图片颜色获取 | Set image color, Get image color

Downloads

100

Readme

color-change

npm Status npm Status install size publish size total downloads

A lightweight JavaScript to change the main color of images, background images, videos and canvases in the page

View demo

Features

  • Features
  • Zero dependencies
  • Very easy to use
  • Multiple color formats
  • Fully accessible
  • Works on all modern browsers (no IE support)

Install

npm install --save color-change

Getting Started

Basic usage

<img class="cc" src="a.jpeg" />
<div class="cc" style="background:url(b.jpeg)"></div>
<video class="cc" src="c.mp4" ></video>
<canvas class="cc"></canvas>
import {ColorChange} from 'color-change'
// Select the element you want to change
let cc = new ColorChange('.cc')

// Change the color & hue of the element into 'red'
cc.setColor('#ff0000')

cc.setColor('#ff0000').then(()=>{
    console.log('set color finish .')
})

Specific cases

img color pick:

import {ColorPick} from 'color-change'
// Get the main color of the img
let cp = new ColorPick(document.querySelector('img'))

cp.getColor().then((color)=>{
    let mainColor=color               // [r,g,b]
})     
cp.getColors(5).then((colors)=>{
    let colorArray=colors             //  [[r,g,b],...]
}) 
// May also use async/await 
let colors=await cp.getColors(5)      // return [[r,g,b],...]

ColorPick + ColorChange:

import {ColorChange,ColorPick} from 'color-change'

let cp = new ColorPick(document.querySelector('img'))

// Get the main color of the img
cp.getColor().then((mainColor)=>{

    // Change video color to img main color
    let cc = new ColorChange('video')

    cc.setColor(mainColor)
})

Option

ColorChange

/**
 * ColorChange(el[,isBrightness][,isSaturate])
 *  el: img,background,video,canvas             // Select the element you want to change
 *  isBrightness: bool                          // Turn on color brightness recognition.
 *  isSaturate: bool                            // Turn on color saturation recognition.
 **/ 
let cc =new ColorChange(el,isBrightness,isSaturate)

// function
cc.setColor('#f00') // set color, rgb(255,0,0)| #ff0000 .., return Promise
cc.clear()          // clear color

ColorPick

/**
 * ColorPick(sourceImage)
 *  sourceImage: img,background,video,canvas         // Want to get source Image of the color
 **/ 
let cp =new ColorPick(sourceImage)

// function
cp.getColor().then((color)=>{ ... })                 // Promise, get mian color, return [r,g,b]
cp.getColors(5).then((colors)=>{ ... })              // Promise, Get colors, return [[r,g,b],...]

Note

cross domain URLs are not supported !!!

Please enable cross domain access of resources on the server or use the proxy

License

Copyright (c) 2022 [email protected]
color-change is licensed under the MIT license.