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.
This property can have the following values:
"srgb" representing the sRGB color space."display-p3" representing the display-p3 color space.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.
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"
| Specification |
|---|
| HTML> # dom-imagedata-colorspace> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
colorSpace |
92 | 92 | No | 78 | 15.2 | 92 | No | 65 | 15.2 | 16.0 | 92 | 15.2 |
CanvasRenderingContext2D.createImageData()CanvasRenderingContext2D.getImageData()colorSpace setting in canvas.getContext()
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ImageData/colorSpace