Public function

Resize an image Blob to be smaller than it is currently.

Example
const image = await(await fetch('/image.jpg')).blob()
const size = await getImageSize(image)
const resizedImage = await downsizeImage(image, size.w / 2, size.h / 2, {
  type: 'image/jpeg',
  quality: 0.92,
})
Signature
function downsizeImage(
  blob: Blob,
  width: number,
  height: number,
  opts?: {
    type?: string | undefined
    quality?: number | undefined
  }
): Promise<Blob>
Parameters
NameDescription

blob

Blob

width

number

The desired width.

height

number

The desired height.

opts

{
  type?: string | undefined
  quality?: number | undefined
}

Options for the image.

Returns
Promise<Blob>
Source

packages/tldraw/src/lib/utils/assets/assets.ts

DialogDrawShapeTool