Skip to content

BlendImage

Image Blend filter class

Example

const filter = new filters.BlendColor({
color: '#000',
mode: 'multiply'
});
const filter = new BlendImage({
image: fabricImageObject,
mode: 'multiply'
});
object.filters.push(filter);
object.applyFilters();
canvas.renderAll();

Extends

Constructors

new BlendImage()

new BlendImage(options?): BlendImage

Constructor

Parameters

options?: object & Partial<BlendImageOwnProps> & Record<string, any> = {}

Options object

Returns

BlendImage

Inherited from

BaseFilter.constructor

Defined in

src/filters/BaseFilter.ts:56

Properties

alpha

alpha: number

alpha value. represent the strength of the blend image operation. not implemented.

Defined in

src/filters/BlendImage.ts:62


image

image: FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>

Image to make the blend operation with.

Defined in

src/filters/BlendImage.ts:45


mode

mode: TBlendImageMode

Blend mode for the filter: either ‘multiply’ or ‘mask’. ‘multiply’ will multiply the values of each channel (R, G, B, and A) of the filter image by their corresponding values in the base image. ‘mask’ will only look at the alpha channel of the filter image, and apply those values to the base image’s alpha channel.

Default

Defined in

src/filters/BlendImage.ts:56


defaults

static defaults: BlendImageOwnProps = blendImageDefaultValues

Overrides

BaseFilter.defaults

Defined in

src/filters/BlendImage.ts:66


type

static type: string = 'BlendImage'

The class type. Used to identify which class this is. This is used for serialization purposes and internally it can be used to identify classes. As a developer you could use instance of Class but to avoid importing all the code and blocking tree shaking we try to avoid doing that.

Overrides

BaseFilter.type

Defined in

src/filters/BlendImage.ts:64


uniformLocations

static uniformLocations: string[]

Contains the uniform locations for the fragment shader. uStepW and uStepH are handled by the BaseFilter, each filter class needs to specify all the one that are needed

Overrides

BaseFilter.uniformLocations

Defined in

src/filters/BlendImage.ts:68

Accessors

type

get type(): Name

Filter type

Default

Returns

Name

Inherited from

BaseFilter.type

Defined in

src/filters/BaseFilter.ts:30

Methods

_setupFrameBuffer()

_setupFrameBuffer(options): void

Parameters

options: TWebGLPipelineState

Returns

void

Inherited from

BaseFilter._setupFrameBuffer

Defined in

src/filters/BaseFilter.ts:204


_swapTextures()

_swapTextures(options): void

Parameters

options: TWebGLPipelineState

Returns

void

Inherited from

BaseFilter._swapTextures

Defined in

src/filters/BaseFilter.ts:231


applyTo()

applyTo(options): void

Apply this filter to the input image data provided.

Determines whether to use WebGL or Canvas2D based on the options.webgl flag.

Parameters

options: TWebGLPipelineState | T2DPipelineState

Returns

void

Inherited from

BaseFilter.applyTo

Defined in

src/filters/BaseFilter.ts:264


applyTo2d()

applyTo2d(options): void

Apply the Blend operation to a Uint8ClampedArray representing the pixels of an image.

Parameters

options: T2DPipelineState

Returns

void

Overrides

BaseFilter.applyTo2d

Defined in

src/filters/BlendImage.ts:122


applyToWebGL()

applyToWebGL(options): void

Apply this filter using webgl.

Parameters

options: TWebGLPipelineState

Returns

void

Overrides

BaseFilter.applyToWebGL

Defined in

src/filters/BlendImage.ts:82


bindAdditionalTexture()

bindAdditionalTexture(gl, texture, textureUnit): void

Parameters

gl: WebGLRenderingContext

texture: WebGLTexture

textureUnit: number

Returns

void

Inherited from

BaseFilter.bindAdditionalTexture

Defined in

src/filters/BaseFilter.ts:333


calculateMatrix()

calculateMatrix(): number[]

Calculate a transformMatrix to adapt the image to blend over

Returns

number[]

Defined in

src/filters/BlendImage.ts:100


createHelpLayer()

createHelpLayer(options): void

If needed by a 2d filter, this functions can create an helper canvas to be used remember that options.targetCanvas is available for use till end of chain.

Parameters

options: T2DPipelineState

Returns

void

Inherited from

BaseFilter.createHelpLayer

Defined in

src/filters/BaseFilter.ts:369


createProgram()

createProgram(gl, fragmentSource, vertexSource): object

Compile this filter’s shader program.

Parameters

gl: WebGLRenderingContext

The GL canvas context to use for shader compilation.

fragmentSource: string = ...

fragmentShader source for compilation

vertexSource: string = ...

vertexShader source for compilation

Returns

object

attributeLocations

attributeLocations: TWebGLAttributeLocationMap

program

program: WebGLProgram

uniformLocations

uniformLocations: TWebGLUniformLocationMap

Inherited from

BaseFilter.createProgram

Defined in

src/filters/BaseFilter.ts:82


createTexture()

createTexture(backend, image): null | WebGLTexture

Parameters

backend: WebGLFilterBackend

image: FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>

Returns

null | WebGLTexture

Defined in

src/filters/BlendImage.ts:90


getAttributeLocations()

getAttributeLocations(gl, program): TWebGLAttributeLocationMap

Return a map of attribute names to WebGLAttributeLocation objects.

Parameters

gl: WebGLRenderingContext

The canvas context used to compile the shader program.

program: WebGLProgram

The shader program from which to take attribute locations.

Returns

TWebGLAttributeLocationMap

A map of attribute names to attribute locations.

Inherited from

BaseFilter.getAttributeLocations

Defined in

src/filters/BaseFilter.ts:152


getCacheKey()

getCacheKey(): string

Returns a string that represent the current selected shader code for the filter. Used to force recompilation when parameters change or to retrieve the shader from cache

Returns

string

Overrides

BaseFilter.getCacheKey

Defined in

src/filters/BlendImage.ts:70


getFragmentSource()

getFragmentSource(): string

Returns

string

Overrides

BaseFilter.getFragmentSource

Defined in

src/filters/BlendImage.ts:74


getUniformLocations()

getUniformLocations(gl, program): TWebGLUniformLocationMap

Return a map of uniform names to WebGLUniformLocation objects.

Parameters

gl: WebGLRenderingContext

The canvas context used to compile the shader program.

program: WebGLProgram

The shader program from which to take uniform locations.

Returns

TWebGLUniformLocationMap

A map of uniform names to uniform locations.

Inherited from

BaseFilter.getUniformLocations

Defined in

src/filters/BaseFilter.ts:168


getVertexSource()

getVertexSource(): string

Returns

string

Overrides

BaseFilter.getVertexSource

Defined in

src/filters/BlendImage.ts:78


isNeutralState()

isNeutralState(options?): boolean

Generic isNeutral implementation for one parameter based filters. Used only in image applyFilters to discard filters that will not have an effect on the image Other filters may need their own version ( ColorMatrix, HueRotation, gamma, ComposedFilter )

Parameters

options?: any

Returns

boolean

Inherited from

BaseFilter.isNeutralState

Defined in

src/filters/BaseFilter.ts:247


retrieveShader()

retrieveShader(options): TWebGLProgramCacheItem

Retrieves the cached shader.

Parameters

options: TWebGLPipelineState

Returns

TWebGLProgramCacheItem

the compiled program shader

Inherited from

BaseFilter.retrieveShader

Defined in

src/filters/BaseFilter.ts:294


sendAttributeData()

sendAttributeData(gl, attributeLocations, aPositionData): void

Send attribute data from this filter to its shader program on the GPU.

Parameters

gl: WebGLRenderingContext

The canvas context used to compile the shader program.

attributeLocations: Record<string, number>

A map of shader attribute names to their locations.

aPositionData: Float32Array

Returns

void

Inherited from

BaseFilter.sendAttributeData

Defined in

src/filters/BaseFilter.ts:191


sendUniformData()

sendUniformData(gl, uniformLocations): void

Send data from this filter to its shader program’s uniforms.

Parameters

gl: WebGLRenderingContext

The GL canvas context used to compile this filter’s shader.

uniformLocations: TWebGLUniformLocationMap

A map of string uniform names to WebGLUniformLocation objects

Returns

void

Overrides

BaseFilter.sendUniformData

Defined in

src/filters/BlendImage.ts:179


toJSON()

toJSON(): object & BlendImageOwnProps

Returns a JSON representation of an instance

Returns

object & BlendImageOwnProps

JSON

Inherited from

BaseFilter.toJSON

Defined in

src/filters/BaseFilter.ts:406


toObject()

toObject(): object & BlendImageOwnProps

Returns object representation of an instance TODO: Handle the possibility of missing image better. As of now a BlendImage filter without image can’t be used with fromObject

Returns

object & BlendImageOwnProps

Object representation of an instance

Overrides

BaseFilter.toObject

Defined in

src/filters/BlendImage.ts:194


unbindAdditionalTexture()

unbindAdditionalTexture(gl, textureUnit): void

Parameters

gl: WebGLRenderingContext

textureUnit: number

Returns

void

Inherited from

BaseFilter.unbindAdditionalTexture

Defined in

src/filters/BaseFilter.ts:344


fromObject()

static fromObject(object, options?): Promise<BaseFilter<"BlendImage", BlendImageOwnProps>>

Create filter instance from an object representation

Parameters

object: Record<string, any>

Object to create an instance from

options?

options.signal?: AbortSignal

handle aborting image loading, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal

Returns

Promise<BaseFilter<"BlendImage", BlendImageOwnProps>>

Static

Overrides

BaseFilter.fromObject

Defined in

src/filters/BlendImage.ts:212