ImageData: colorSpace property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Web Workers.

The read-only ImageData.colorSpace property is a string indicating the color space of the image data.

The color space can be set during ImageData initialization using either the ImageData() constructor or the createImageData() method.

Value

This property can have the following values:

Examples

Getting the color space of canvas image data

The getImageData() method allows you to explicitly request a color space. If it doesn't match the color space the canvas was initialized with, a conversion will be performed. Use the colorSpace property to know which color space your ImageData object is in.

js
const context = canvas.getContext("2d", { colorSpace: "display-p3" });
context.fillStyle = "color(display-p3 0.5 0 0)";
context.fillRect(0, 0, 10, 10);

const p3ImageData = context.getImageData(0, 0, 1, 1);
console.log(p3ImageData.colorSpace); // "display-p3"

const srgbImageData = context.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
console.log(srgbImageData.colorSpace); // "srgb"

Specifications

Specification
HTML
# dom-imagedata-colorspace

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
colorSpace
Chrome – Full support
Chrome 92 (Release date: 2021-07-20)
footnote Full support
Edge – Full support
Edge 92 (Release date: 2021-07-22)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 78 (Release date: 2021-08-03)
footnote Full support
Safari – Full support
Safari 15.2 (Release date: 2021-12-13)
footnote Full support
Chrome Android – Full support
Chrome Android 92 (Release date: 2021-07-20)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 65 (Release date: 2021-10-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.2 (Release date: 2021-12-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 16 (Release date: 2021-11-25)
footnote Full support
WebView Android – Full support
WebView Android 92 (Release date: 2021-07-20)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.2 (Release date: 2021-12-13)
footnote Full support
Deno – Full support
Deno 1.39 (Release date: 2023-12-14)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also