getCompressedJpegFromCanvas Function

Beta  

Produce a jpeg compressed to no more than specified bytes and of no less than specified quality.

getCompressedJpegFromCanvas(canvas: HTMLCanvasElement, maxBytes: number = 60000, minCompressionQuality: number = 0.1): string | undefined

Parameter Type Description
canvas HTMLCanvasElement image source
maxBytes number Maximum size of output image in bytes.
minCompressionQuality number A Number between 0 and 1 indicating the image quality.

Returns - string | undefined

Data URL for compressed jpeg or undefined if criteria could not be met.

Defined in

Last Updated: 13 June, 2024