Color

fabric. Color

new Color(color) → {fabric.Color}

Source:
Tutorials:
Color class The purpose of fabric.Color is to abstract and encapsulate common color operations; fabric.Color is a constructor and creates instances of fabric.Color objects.
Parameters:
Name Type Description
color String optional in hex or rgb(a) or hsl format or from known color list
Returns:
thisArg
Type
fabric.Color

Members

(static) colorNameMap

Source:
Map of the 148 color names with HEX code

(static) reHex

Source:
Regex matching color in HEX format (ex: #FF5544CC, #FF5555, 010155, aff)

(static) reHSLa

Source:
Regex matching color in HSL or HSLA formats (ex: hsl(200, 80%, 10%), hsla(300, 50%, 80%, 0.5), hsla( 300 , 50% , 80% , 0.5 ))

(static) reRGBa

Source:
Regex matching color in RGB or RGBA formats (ex: rgb(0, 0, 0), rgba(255, 100, 10, 0.5), rgba( 255 , 100 , 10 , 0.5 ), rgb(1,1,1), rgba(100%, 60%, 10%, 0.5))

Methods

(static) fromHex(color) → {fabric.Color}

Source:
Returns new color object, when given a color in HEX format
Parameters:
Name Type Description
color String Color value ex: FF5555
Returns:
Type
fabric.Color

(static) fromHsl(color) → {fabric.Color}

Source:
Returns new color object, when given a color in HSL format
Parameters:
Name Type Description
color String Color value ex: hsl(0-260,0%-100%,0%-100%)
Returns:
Type
fabric.Color

(static) fromHsla(color) → {fabric.Color}

Source:
Returns new color object, when given a color in HSLA format
Parameters:
Name Type Description
color String
Returns:
Type
fabric.Color

(static) fromRgb(color) → {fabric.Color}

Source:
Returns new color object, when given a color in RGB format
Parameters:
Name Type Description
color String Color value ex: rgb(0-255,0-255,0-255)
Returns:
Type
fabric.Color

(static) fromRgba(color) → {fabric.Color}

Source:
Returns new color object, when given a color in RGBA format
Parameters:
Name Type Description
color String
Returns:
Type
fabric.Color

(static) fromSource(source) → {fabric.Color}

Source:
Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5])
Parameters:
Name Type Description
source Array
Returns:
Type
fabric.Color

(static) sourceFromHex(color) → {Array}

Source:
Returns array representation (ex: [100, 100, 200, 1]) of a color that's in HEX format
Parameters:
Name Type Description
color String ex: FF5555 or FF5544CC (RGBa)
Returns:
source
Type
Array

(static) sourceFromHsl(color) → {Array}

Source:
See:
Returns array representation (ex: [100, 100, 200, 1]) of a color that's in HSL or HSLA format. Adapted from https://github.com/mjijackson
Parameters:
Name Type Description
color String Color value ex: hsl(0-360,0%-100%,0%-100%) or hsla(0-360,0%-100%,0%-100%, 0-1)
Returns:
source
Type
Array

(static) sourceFromRgb(color) → {Array}

Source:
Returns array representation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format
Parameters:
Name Type Description
color String Color value ex: rgb(0-255,0-255,0-255), rgb(0%-100%,0%-100%,0%-100%)
Returns:
source
Type
Array

getAlpha() → {Number}

Source:
Gets value of alpha channel for this color
Returns:
0-1
Type
Number

getSource() → {Array}

Source:
Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])
Returns:
Type
Array

overlayWith(otherColor) → {fabric.Color}

Source:
Overlays color with another color
Parameters:
Name Type Description
otherColor String | fabric.Color
Returns:
thisArg
Type
fabric.Color

setAlpha(alpha) → {fabric.Color}

Source:
Sets value of alpha channel for this color
Parameters:
Name Type Description
alpha Number Alpha value 0-1
Returns:
thisArg
Type
fabric.Color

setSource(source)

Source:
Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1])
Parameters:
Name Type Description
source Array

toBlackWhite(threshold) → {fabric.Color}

Source:
Transforms color to its black and white representation
Parameters:
Name Type Description
threshold Number
Returns:
thisArg
Type
fabric.Color

toGrayscale() → {fabric.Color}

Source:
Transforms color to its grayscale representation
Returns:
thisArg
Type
fabric.Color

toHex() → {String}

Source:
Returns color representation in HEX format
Returns:
ex: FF5555
Type
String

toHexa() → {String}

Source:
Returns color representation in HEXA format
Returns:
ex: FF5555CC
Type
String

toHsl() → {String}

Source:
Returns color representation in HSL format
Returns:
ex: hsl(0-360,0%-100%,0%-100%)
Type
String

toHsla() → {String}

Source:
Returns color representation in HSLA format
Returns:
ex: hsla(0-360,0%-100%,0%-100%,0-1)
Type
String

toRgb() → {String}

Source:
Returns color representation in RGB format
Returns:
ex: rgb(0-255,0-255,0-255)
Type
String

toRgba() → {String}

Source:
Returns color representation in RGBA format
Returns:
ex: rgba(0-255,0-255,0-255,0-1)
Type
String