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

get-contrast-ratio-plus

v1.0.2

Published

This package could get the contrast ratio between two colors, one color & the main color of an image, or the top-2 main colors of an image.

Downloads

16

Readme

get-contrast-ratio-plus

获取2个色值、1个色值与图像的主题色、图像的主次色的对比度。 This package could get the contrast ratio between two colors, one color & the theme color of an image, or the top-2 theme colors of an image.

Install

npm install get-contrast-ratio-plus

Usage

Tip: use Promise/await

const getContrastRatio = require('get-contrast-ratio-plus')

// 计算所传入2个色值的对比度。支持多种色值格式,例如:rgb、rgba、hsl
// Calculate the contrast ratio of the 2 colors ​passed in.Support multiple color formats, such as rgb, rgba, hsl, etc.
const twoColors = await getContrastRatio('#ffffff', '#000000')

// 计算传入的1个色值与指定图片主题色的对比度。需传入图片url、初始坐标x、初始坐标y、区域宽度width、区域宽度height构成的对象
// Calculate the contrast ratio between the input color and the specified image theme color. 
// The object composed of image's url, initial coordinate x, initial coordinate y, area width width, and area width height needs to be passed in.
const oneColorOneImage = await getContrastRatio('#ffffff', { url: 'picture.png', x: 0, y: 0, width: 100, height: 100 })

// 计算图片部分区域的主次色对比度
// Calculate the contrast ratio of the top-2 theme colors of part of the image.
const partOfSingleImage = await getContrastRatio({ url: 'picture.png', x: 0, y: 0, width: 100, height: 100 })

// 可省略x、y、width、height等信息,此时默认求整个图片的主次色对比度
// Information such as x, y, width, and height could be omitted.
// Then calculate the contrast ratio of the top-2 theme colors of the entire image by default.
const singleImage = await getContrastRatio({ url: 'picture.png' })