Skip to content

BlendImage

Defined in: src/filters/BlendImage.ts:41

Image Blend filter class

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();

new BlendImage(options?): BlendImage

Defined in: src/filters/BaseFilter.ts:57

Constructor

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

Options object

BlendImage

BaseFilter.constructor

alpha: number

Defined in: src/filters/BlendImage.ts:62

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


image: FabricImage

Defined in: src/filters/BlendImage.ts:45

Image to make the blend operation with.


mode: TBlendImageMode

Defined in: src/filters/BlendImage.ts:56

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.


static defaults: BlendImageOwnProps = blendImageDefaultValues

Defined in: src/filters/BlendImage.ts:66

BaseFilter.defaults


static type: string = 'BlendImage'

Defined in: src/filters/BlendImage.ts:64

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.

BaseFilter.type


static uniformLocations: string[]

Defined in: src/filters/BlendImage.ts:68

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

BaseFilter.uniformLocations

get type(): Name

Defined in: src/filters/BaseFilter.ts:31

Filter type

Name

BaseFilter.type

_setupFrameBuffer(options): void

Defined in: src/filters/BaseFilter.ts:205

TWebGLPipelineState

void

BaseFilter._setupFrameBuffer


_swapTextures(options): void

Defined in: src/filters/BaseFilter.ts:232

TWebGLPipelineState

void

BaseFilter._swapTextures


applyTo(options): void

Defined in: src/filters/BaseFilter.ts:265

Apply this filter to the input image data provided.

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

TWebGLPipelineState | T2DPipelineState

void

BaseFilter.applyTo


applyTo2d(options): void

Defined in: src/filters/BlendImage.ts:122

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

T2DPipelineState

void

BaseFilter.applyTo2d


applyToWebGL(options): void

Defined in: src/filters/BlendImage.ts:82

Apply this filter using webgl.

TWebGLPipelineState

void

BaseFilter.applyToWebGL


bindAdditionalTexture(gl, texture, textureUnit): void

Defined in: src/filters/BaseFilter.ts:334

WebGLRenderingContext

WebGLTexture

number

void

BaseFilter.bindAdditionalTexture


calculateMatrix(): number[]

Defined in: src/filters/BlendImage.ts:100

Calculate a transformMatrix to adapt the image to blend over

number[]


createHelpLayer(options): void

Defined in: src/filters/BaseFilter.ts:370

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.

T2DPipelineState

void

BaseFilter.createHelpLayer


createProgram(gl, fragmentSource, vertexSource): object

Defined in: src/filters/BaseFilter.ts:83

Compile this filter’s shader program.

WebGLRenderingContext

The GL canvas context to use for shader compilation.

string = ...

fragmentShader source for compilation

string = ...

vertexShader source for compilation

object

attributeLocations: TWebGLAttributeLocationMap

program: WebGLProgram

uniformLocations: TWebGLUniformLocationMap

BaseFilter.createProgram


createTexture(backend, image): null | WebGLTexture

Defined in: src/filters/BlendImage.ts:90

WebGLFilterBackend

FabricImage

null | WebGLTexture


getAttributeLocations(gl, program): TWebGLAttributeLocationMap

Defined in: src/filters/BaseFilter.ts:153

Return a map of attribute names to WebGLAttributeLocation objects.

WebGLRenderingContext

The canvas context used to compile the shader program.

WebGLProgram

The shader program from which to take attribute locations.

TWebGLAttributeLocationMap

A map of attribute names to attribute locations.

BaseFilter.getAttributeLocations


getCacheKey(): string

Defined in: src/filters/BlendImage.ts:70

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

string

BaseFilter.getCacheKey


getFragmentSource(): string

Defined in: src/filters/BlendImage.ts:74

string

BaseFilter.getFragmentSource


getUniformLocations(gl, program): TWebGLUniformLocationMap

Defined in: src/filters/BaseFilter.ts:169

Return a map of uniform names to WebGLUniformLocation objects.

WebGLRenderingContext

The canvas context used to compile the shader program.

WebGLProgram

The shader program from which to take uniform locations.

TWebGLUniformLocationMap

A map of uniform names to uniform locations.

BaseFilter.getUniformLocations


getVertexSource(): string

Defined in: src/filters/BlendImage.ts:78

string

BaseFilter.getVertexSource


isNeutralState(options?): boolean

Defined in: src/filters/BaseFilter.ts:248

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 )

any

boolean

BaseFilter.isNeutralState


retrieveShader(options): TWebGLProgramCacheItem

Defined in: src/filters/BaseFilter.ts:295

Retrieves the cached shader.

TWebGLPipelineState

TWebGLProgramCacheItem

the compiled program shader

BaseFilter.retrieveShader


sendAttributeData(gl, attributeLocations, aPositionData): void

Defined in: src/filters/BaseFilter.ts:192

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

WebGLRenderingContext

The canvas context used to compile the shader program.

Record<string, number>

A map of shader attribute names to their locations.

Float32Array

void

BaseFilter.sendAttributeData


sendUniformData(gl, uniformLocations): void

Defined in: src/filters/BlendImage.ts:179

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

WebGLRenderingContext

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

TWebGLUniformLocationMap

A map of string uniform names to WebGLUniformLocation objects

void

BaseFilter.sendUniformData


toJSON(): object & BlendImageOwnProps

Defined in: src/filters/BaseFilter.ts:407

Returns a JSON representation of an instance

object & BlendImageOwnProps

JSON

BaseFilter.toJSON


toObject(): object & BlendImageOwnProps

Defined in: src/filters/BlendImage.ts:194

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

object & BlendImageOwnProps

Object representation of an instance

BaseFilter.toObject


unbindAdditionalTexture(gl, textureUnit): void

Defined in: src/filters/BaseFilter.ts:345

WebGLRenderingContext

number

void

BaseFilter.unbindAdditionalTexture


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

Defined in: src/filters/BlendImage.ts:212

Create filter instance from an object representation

Record<string, any>

Object to create an instance from

AbortSignal

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

Promise<BaseFilter<"BlendImage", BlendImageOwnProps, BlendImageOwnProps>>

BaseFilter.fromObject