files/en-us/web/api/offscreencanvas/converttoblob/index.md
{{APIRef("Canvas API")}}{{AvailableInWorkers}}
The OffscreenCanvas.convertToBlob() method creates a {{domxref("Blob")}} object representing the image contained in the canvas.
The desired file format and image quality may be specified.
If the file format is not specified, or if the given format is not supported, then the data will be exported as image/png.
Browsers are required to support image/png; many will support additional formats including image/jpeg and image/webp.
The created image will have a resolution of 96dpi for file formats that support encoding resolution metadata.
convertToBlob()
convertToBlob(options)
options {{optional_inline}}
type
image/png; this image format will be also used if the specified type is not supported.quality
0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp).
A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.A {{jsxref("Promise")}} returning a {{domxref("Blob")}} object representing the image contained in the canvas.
The promise may be rejected with the following exceptions:
InvalidStateError {{domxref("DOMException")}}
OffscreenCanvas is not detached; in other words it still associated with the DOM and not the current worker.SecurityError {{domxref("DOMException")}}
IndexSizeError {{domxref("DOMException")}}
EncodingError {{domxref("DOMException")}}
const offscreen = new OffscreenCanvas(256, 256);
const gl = offscreen.getContext("webgl");
// Perform some drawing using the gl context
offscreen.convertToBlob().then((blob) => console.log(blob));
// Blob { size: 334, type: "image/png" }
{{Specifications}}
{{Compat}}