an image source can be an HTMLImageElement
, HTMLCanvasElement
, ImageBitmap
, etc..
Optional
width: numberOptional
crop_rect: Rectdimension of the cropping rectangle. leave as undefined
if you wish not to crop, or only provide a partial Rect
Optional
bitmap_options: ImageBitmapOptionsOptional
image_data_options: ImageDataSettings
extract the ImageData from an image source (of type CanvasImageSource), with optional cropping.
due to the fact that this function utilizes a
Canvas
/OffscreenCanvas
, it is important to note that the outputImageData
is sometimes lossy in nature. this is because gpu-accelerated web-browsers approximate the colors (i.e. you don't truly get256^3
unique colors), and also due to rounding errors from/to internal float-valued colors and output integer-valued colors.but generally speaking, the
ImageData
can be lossless if all of the following are satisfied:flags
page ("chrome://flags"
or"about:config"
).img_src
has either no alpha-channel, or 100% visible alpha-channel throughout (i.e. non-transparent image).