downsizeImage

See source code

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

function downsizeImage(
  blob: Blob,
  width: number,
  height: number,
  opts?: {
    quality?: number | undefined;
    type?: string | undefined;
  },
): Promise<Blob>;

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.85,
});

Parameters

NameDescription

blob

Blob;

width

number;

The desired width.

height

number;

The desired height.

opts

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

Options for the image.

Returns

Promise<Blob>;
Prev
defaultHandleExternalUrlContent
Next
exportAs