New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

color-blend

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-blend

Blends RGBA colors with different blend modes

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
increased by2.19%
Maintainers
1
Weekly downloads
 
Created
Source

color-blend

Greenkeeper badge

Blends RGBA colors with different blend modes

JavaScript implementation of the blend modes introduced in the W3C Compositing and Blending spec.

Install

$ npm install color-blend --save

Usage

Example

It's simple to wrap your head around, you should get it after just reading this:

var blender = require('color-blend')

// Mix red and lime green
var backdrop = { r: 255, g: 0,   b: 0, a: 0.6 }
var source   = { r: 0,   g: 255, b: 0, a: 0.4 }

blender.normal(backdrop, source)
// Returns { r: 121, g: 134, b: 0, a: 0.76 }

Explanation

This module exports an object—let's agree on calling it blender in this guide—which provides all blend modes listed in the W3C document as methods. Those are: normal, multiply, screen, overlay, darken, lighten, colorDodge, colorBurn, hardLight, softLight, difference, exclusion, hue, saturation, color and luminosity.

They all work the same: Each of these methods takes a backdrop color and a source color as arguments. Those parameters are expected to be RGBA colors represented as plain objects containing the keys r, g, b (each ranging from 0 to 255) and a (ranging from 0 to 1).

The result of the blending operation will be returned as such an RGBA object as well.

Options

The blender also has an options property containing the default blending settings. Change those if you'd like to alter the behaviour of the module.

Here's the default options:

{

  // Set this to true if you want to provide color channel values from 0 to 1 instead of 0 to 255
  unitInput: false,

  // As in the above, but for the result
  unitOutput: false,

  // Set this to false if the result color channel values should not be rounded (only applies if `unitOutput` is false)
  roundOutput: true

}

Keywords

FAQs

Package last updated on 15 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc