an image source can be an HTMLImageElement, HTMLCanvasElement, ImageBitmap, etc..
Optionalwidth: numberOptionalcrop_rect: Rectdimension of the cropping rectangle. leave as undefined if you wish not to crop, or only provide a partial Rect
Optionalbitmap_options: ImageBitmapOptionsOptionalimage_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 outputImageDatais sometimes lossy in nature. this is because gpu-accelerated web-browsers approximate the colors (i.e. you don't truly get256^3unique colors), and also due to rounding errors from/to internal float-valued colors and output integer-valued colors.but generally speaking, the
ImageDatacan be lossless if all of the following are satisfied:flagspage ("chrome://flags"or"about:config").img_srchas either no alpha-channel, or 100% visible alpha-channel throughout (i.e. non-transparent image).