Skip to main content

Blending

When blending two colors, the amount ∈ [0,1] refers to the percentage the second color is blended with the first. In other words, 0 means 0% of the second color and 100% of the first while 1 means 100% of the second color and 0% of the first.

.modify('blend', {
with: color2, // REQUIRED, can be any color of any type
amount: number, // optional, 0 - 1, defaults to 0.5
method: string, // optional, defaults to the original type or 'rgb' if type not directly supported
round: boolean, // optional, defaults to true
})

Blending Methods

methoddescription
rgbBlends each RGBA value
hsvBlends each HSVA value
hslBlends each HSLA value
hspBlends each HSPA value
cmykBlends each CMYK value
labBlends each L*a*b* value
luvBlends each L*u*v* value
hueBlends hue only
valueBlends value (HSV) only
lightnessBlends lightness (HSL) only
intensityBlends intensity (HSI) only
perceivedbrightnessBlends perceived brightness (HSP) only
screenRGB values are inverted, multiplied, then inverted again
multiplyRGB values are multiplied
overlayScreen or multiply depending on whether second color values are lighter or darker
softlightSimilar to overlay; uses W3C formula
divideFirst color values divided by second
subtractionSecond color values subtracted from first color
differenceDifference between each value pair
colorburnDivites inverted bottom layer by top layer
colordodgeDivides bottom layer by inverted top layer
vividlightColor dodge or burn, depending on which value is lighter
linearburnSums each value pair and subtracts 1
lineardodgeSums each value pair
linearlightLinear dodge or burn, depending on which value is lighter

See mathematics for more details

JavaScript

const Color = require('chromaticity-color-utilities')

const color1 = Color.from('rgb', [255, 0, 0]).modify('blend', {
with: Color.from('hex', '00ff00')
// method defaults to type of color1 (rgb)
})
// rgb { r: 128, g: 128, b: 0, a: 255, bitDepth: 8, max: 255 }

const color2 = Color.from('rgb', [255, 0, 0]).modify('blend', {
with: Color.from('hex', '00ff00'),
method: 'hsv',
})
// rgb { r: 255, g: 255, b: 0, a: 255, bitDepth: 8, max: 255 }

const color2 = Color.from('hsv', [300, 100, 100]).modify('blend', {
with: Color.from('hex', '00ff00')
// method defaults to type of color2 (hsv)
})
// hsv { h: 210, s: 100, v: 100, a: 100 }

const color3 = Color.from('hex', 'ee5432')
.modify('blend', {
with: Color.from('rgb', [234, 100, 20, 64]),
amount: 1 / 3,
})
.to('hsv')
// hsv { h: 15, s: 83, v: 93, a: 75 }

TypeScript

import Color from 'chromaticity-color-utilities'

const color1: Color.rgb[] = Color.from('rgb', [255, 0, 0]).modify('blend', {
with: Color.from('hex', '00ff00'),
method: 'vividlight'
})