Function constructImageData

  • extract the ImageData from an image source (of type CanvasImageSource), with optional cropping.
    due to the fact that this function utilizes a canvas, it is important to note that the output ImageData is sometimes lossy in nature, because gpu-accelerated web-browsers approximate the 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:

    • disable gpu-acceleration of your web-browser, through the flags page
    • your img_src has either no alpha-channel, or 100% visible alpha-channel throughout (ie non-transparent image)
    • you have pre-multiplied alpha disabled (this part can be achieved by this library, but I haven't looked into it yet) also check out script for using webgl for reading and writing bitmap pixels without losing color accuracy due to alpha premultiplication

    Parameters

    • img_src: AnyImageSource

      an image source can be an HTMLImageElement, HTMLCanvasElement, ImageBitmap, etc..

    • Optional width: number
    • Optional crop_rect: Rect

      dimension of the cropping rectangle. leave as undefined if you wish not to crop, or only provide a partial Rect

    • Optional bitmap_options: ImageBitmapOptions
    • Optional image_data_options: ImageDataSettings

    Returns Promise<ImageData>

Generated using TypeDoc