getCompressedJpegFromCanvas Function

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 Canvas containing the image to be compressed.
maxBytes number Maximum size of output jpeg in bytes.
minCompressionQuality number The minimum acceptable image quality as a number between 0 (lowest quality) and 1 (highest quality).

Returns - string | undefined

A data URL for the image, or undefined if the compression and size constraints could not be met.

Defined in

Last Updated: 29 November, 2022