getCompressedJpegFromCanvas Function

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

getCompressedJpegFromCanvas(canvas: HTMLCanvasElement, maxBytes: number60000, minCompressionQuality: number0.1): string | undefined

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

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: 14 November, 2024