OffscreenCanvas.convertToBlob()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The OffscreenCanvas.convertToBlob() method creates a Blob object representing the image contained in the canvas.

Syntax

Promise<Blob> OffscreenCanvas.convertToBlob(options);

Parameters

optionsOptional

You can specify several options when converting your OffscreenCanvas object into a Blob object, for example:

const blob = offscreenCanvas.convertToBlob({
  type: "image/jpeg",
  quality: 0.95
});

options:

  • type: A DOMString indicating the image format. The default type is image/png.
  • quality: A Number between 0 and 1 indicating image quality if the type option is image/jpeg or image/webp. If this argument is anything else, the default value for image quality is used. Other arguments are ignored.

Return value

A Promise returning a Blob object representing the image contained in the canvas.

Examples

var offscreen = new OffscreenCanvas(256, 256);
var gl = offscreen.getContext("webgl");

// ... some drawing using the gl context ...

offscreen.convertToBlob().then(function(blob) {
  console.log(blob);
});

// Blob { size: 334, type: "image/png" }

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
convertToBlob
69
79
46
No
56
No
No
69
46
48
No
10.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/convertToBlob