WorkerGlobalScope: createImageBitmap() method
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
* Some parts of this feature may have varying levels of support.
Note: This feature is only available inWeb Workers.
ThecreateImageBitmap() method of theWorkerGlobalScope interface creates a bitmap from a given source, optionally cropped to contain only a portion of that source.It accepts a variety of different image sources, and returns aPromise which resolves to anImageBitmap.
In this article
Syntax
createImageBitmap(image)createImageBitmap(image, options)createImageBitmap(image, sx, sy, sw, sh)createImageBitmap(image, sx, sy, sw, sh, options)Parameters
imageAn image source, which can be any one of the following:
sxThe x coordinate of the reference point of the rectangle from which the
ImageBitmapwill be extracted.syThe y coordinate of the reference point of the rectangle from which the
ImageBitmapwill be extracted.swThe width of the rectangle from which the
ImageBitmapwill be extracted.This value can be negative.shThe height of the rectangle from which the
ImageBitmapwill be extracted. This value can be negative.optionsOptionalAn object that sets options for the image's extraction.The available options are:
imageOrientationSpecifies how the bitmap image should be oriented.
from-imageImage oriented according to EXIF orientation metadata, if present (default).
flipYImage oriented according to EXIF orientation metadata, if present, and then flipped vertically.
noneImage oriented according to image encoding, ignoring any metadata about the orientation (such as EXIF metadata, that might be added to an image to indicate that the camera was turned sideways to capture the image in portrait mode).
premultiplyAlphaSpecifies whether the bitmap's color channels should be premultiplied by the alpha channel.One of
none,premultiply, ordefault(default).colorSpaceConversionSpecifies whether the image should be decoded using color space conversion.Either
noneordefault(default).The valuedefaultindicates that implementation-specific behavior is used.resizeWidthA long integer that indicates the output width.
resizeHeightA long integer that indicates the output height.
resizeQualitySpecifies the algorithm to be used for resizing the input to match the output dimensions.One of
pixelated,low(default),medium, orhigh.
Return value
APromise which resolves to anImageBitmap object containing bitmap data from the given rectangle.
Examples
SeeWindow.createImageBitmap() for examples.
Specifications
| Specification |
|---|
| HTML> # dom-createimagebitmap-dev> |