Skip to content

Resize

Resize image filter class

Example

const filter = new Resize();
object.filters.push(filter);
object.applyFilters(canvas.renderAll.bind(canvas));

Extends

Constructors

new Resize()

new Resize(options?): Resize

Constructor

Parameters

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

Options object

Returns

Resize

Inherited from

BaseFilter.constructor

Defined in

src/filters/BaseFilter.ts:57

Properties

lanczosLobes

lanczosLobes: number

LanczosLobes parameter for lanczos filter, valid for resizeType lanczos

Param

Default

Defined in

src/filters/Resize.ts:80


resizeType

resizeType: TResizeType

Resize type for webgl resizeType is just lanczos, for canvas2d can be: bilinear, hermite, sliceHack, lanczos.

Default

Defined in

src/filters/Resize.ts:59


scaleX

scaleX: number

Scale factor for resizing, x axis

Param

Default

Defined in

src/filters/Resize.ts:66


scaleY

scaleY: number

Scale factor for resizing, y axis

Param

Default

Defined in

src/filters/Resize.ts:73


defaults

static defaults: ResizeOwnProps = resizeDefaultValues

Overrides

BaseFilter.defaults

Defined in

src/filters/Resize.ts:84


type

static type: string = 'Resize'

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/Resize.ts:82


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/Resize.ts:86

Accessors

type

get type(): Name

Filter type

Default

Returns

Name

Inherited from

BaseFilter.type

Defined in

src/filters/BaseFilter.ts:31

Methods

_setupFrameBuffer()

_setupFrameBuffer(options): void

Parameters

options: TWebGLPipelineState

Returns

void

Inherited from

BaseFilter._setupFrameBuffer

Defined in

src/filters/BaseFilter.ts:205


_swapTextures()

_swapTextures(options): void

Parameters

options: TWebGLPipelineState

Returns

void

Inherited from

BaseFilter._swapTextures

Defined in

src/filters/BaseFilter.ts:232


applyTo()

applyTo(options): void

Apply the resize filter to the image Determines whether to use WebGL or Canvas2D based on the options.webgl flag.

Parameters

options: TWebGLPipelineState | T2DPipelineState

Returns

void

Overrides

BaseFilter.applyTo

Defined in

src/filters/Resize.ts:197


applyTo2d()

applyTo2d(this, options): void

Parameters

this: ResizeDuring2DResize

options: T2DPipelineState

Returns

void

Overrides

BaseFilter.applyTo2d

Defined in

src/filters/Resize.ts:223


applyToForWebgl()

applyToForWebgl(this, options): void

Parameters

this: ResizeDuringWEBGLResize

options: TWebGLPipelineState

Returns

void

Defined in

src/filters/Resize.ts:163


applyToWebGL()

applyToWebGL(options): void

Apply this filter using webgl.

Parameters

options: TWebGLPipelineState

Returns

void

Inherited from

BaseFilter.applyToWebGL

Defined in

src/filters/BaseFilter.ts:315


bilinearFiltering()

bilinearFiltering(this, options, oW, oH, dW, dH): ImageData

bilinearFiltering

Parameters

this: ResizeDuring2DResize

options: T2DPipelineState

oW: number

Original Width

oH: number

Original Height

dW: number

Destination Width

dH: number

Destination Height

Returns

ImageData

Defined in

src/filters/Resize.ts:417


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:334


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:370


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:83


generateShader()

generateShader(filterWindow): string

Generate vertex and shader sources from the necessary steps numbers

Parameters

filterWindow: number

Returns

string

Defined in

src/filters/Resize.ts:136


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:153


getCacheKey()

getCacheKey(this): 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

Parameters

this: ResizeDuringWEBGLResize

Returns

string

Overrides

BaseFilter.getCacheKey

Defined in

src/filters/Resize.ts:111


getFilterWindow()

getFilterWindow(this): number

Parameters

this: ResizeDuringWEBGLResize

Returns

number

Defined in

src/filters/Resize.ts:106


getFragmentSource()

getFragmentSource(this): string

Parameters

this: ResizeDuringWEBGLResize

Returns

string

Overrides

BaseFilter.getFragmentSource

Defined in

src/filters/Resize.ts:116


getTaps()

getTaps(this): any[]

Parameters

this: ResizeDuringWEBGLResize

Returns

any[]

Defined in

src/filters/Resize.ts:121


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:169


getVertexSource()

getVertexSource(): string

Returns

string

Inherited from

BaseFilter.getVertexSource

Defined in

src/filters/BaseFilter.ts:72


hermiteFastResize()

hermiteFastResize(this, options, oW, oH, dW, dH): ImageData

hermiteFastResize

Parameters

this: ResizeDuring2DResize

options: T2DPipelineState

oW: number

Original Width

oH: number

Original Height

dW: number

Destination Width

dH: number

Destination Height

Returns

ImageData

Defined in

src/filters/Resize.ts:480


isNeutralState()

isNeutralState(): 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 )

Returns

boolean

Overrides

BaseFilter.isNeutralState

Defined in

src/filters/Resize.ts:205


lanczosCreate()

lanczosCreate(lobes): (x) => number

Parameters

lobes: number

Returns

Function

Parameters

x: number

Returns

number

Defined in

src/filters/Resize.ts:209


lanczosResize()

lanczosResize(this, options, oW, oH, dW, dH): ImageData

Filter lanczosResize

Parameters

this: ResizeDuring2DResize

options: T2DPipelineState

oW: number

Original Width

oH: number

Original Height

dW: number

Destination Width

dH: number

Destination Height

Returns

ImageData

Defined in

src/filters/Resize.ts:326


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:295


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:192


sendUniformData()

sendUniformData(this, gl, uniformLocations): void

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

Parameters

this: ResizeDuringWEBGLResize

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/Resize.ts:94


sliceByTwo()

sliceByTwo(options, oW, oH, dW, dH): ImageData

Filter sliceByTwo

Parameters

options: T2DPipelineState

oW: number

Original Width

oH: number

Original Height

dW: number

Destination Width

dH: number

Destination Height

Returns

ImageData

Defined in

src/filters/Resize.ts:261


toJSON()

toJSON(): object & ResizeOwnProps

Returns a JSON representation of an instance

Returns

object & ResizeOwnProps

JSON

Inherited from

BaseFilter.toJSON

Defined in

src/filters/BaseFilter.ts:407


toObject()

toObject(): object & ResizeOwnProps

Returns object representation of an instance It will automatically export the default values of a filter, stored in the static defaults property.

Returns

object & ResizeOwnProps

Object representation of an instance

Inherited from

BaseFilter.toObject

Defined in

src/filters/BaseFilter.ts:387


unbindAdditionalTexture()

unbindAdditionalTexture(gl, textureUnit): void

Parameters

gl: WebGLRenderingContext

textureUnit: number

Returns

void

Inherited from

BaseFilter.unbindAdditionalTexture

Defined in

src/filters/BaseFilter.ts:345


fromObject()

static fromObject(__namedParameters, _options): Promise<BaseFilter<string, object, object>>

Parameters

__namedParameters: Record<string, any>

_options: Abortable

Returns

Promise<BaseFilter<string, object, object>>

Inherited from

BaseFilter.fromObject

Defined in

src/filters/BaseFilter.ts:412