Skip to main content

Image loader

Decode pixels into the browser’s portable image type.

ImageLoader is the preferred image loader for new code. It turns common encoded image files into ImageBitmap values in supported browsers and through the loaders.gl polyfill path under Node.js.

The image path

Read encoded bytes. Decode once. Hand pixels to the application.

The loader keeps environment-specific decoding at the boundary. Applications can use the same output shape in rendering, analysis, and image conversion code.

Input

PNG, JPEG, GIF, WebP, AVIF, BMP, ICO, or SVG

Decode

Browser `createImageBitmap` or Node polyfill

Output

An `ImageBitmap` value

Next step

Read pixels with `getImageData` or render directly

From-v5.0

The preferred image loader for new code. ImageLoader returns ImageBitmap in supported browsers and under Node.js when @loaders.gl/core/polyfills is installed.

Detailed guide

Decode and portability details

The reference below covers supported image formats, output behavior, browser options, Node.js polyfills, and portability limitations.

ImageLoader
File Extension.png, .jpg, .jpeg, .gif, .webp, .avif, .bmp, .ico, .svg
File TypeBinary
File FormatPNG, JPEG, GIF, WEBP, AVIF, BMP, SVG
Data FormatImageBitmap
Supported APIsload, parse
Worker Thread❌ No (but may run on separate native thread in browsers)
Streaming❌ No

ImageLoader was previously named ImageBitmapLoader. Use ImageLoaderOptions for bitmap options.

Usage​

import '@loaders.gl/core/polyfills'; // only needed if using under Node
import {ImageLoader} from '@loaders.gl/images/image';
import {load} from '@loaders.gl/core';

const image = await load(url, ImageLoader, options);

Data Format​

ImageLoader parses binary encoded images (such as JPEG or PNG images) into:

  • ImageBitmap in browsers with createImageBitmap support.
  • A minimal ImageBitmap polyfill under Node.js via @loaders.gl/core/polyfills.

If application code needs raw pixels, load with ImageLoader and then call getImageData(image).

Options​

OptionTypeDefaultDescription
image.typestringunsetOptional compatibility alias. Only imagebitmap is accepted. Legacy values now throw.

ImageBitmap Options​

Pass through options to createImageBitmap with the top-level options.imagebitmap object.

OptionTypeDefaultDescription
imagebitmap.imageOrientationstring'none'image should be flipped vertically. Either 'none' or 'flipY'.
imagebitmap.premultiplyAlphastring'default'Premultiply color channels by the alpha channel. One of 'none', 'premultiply', or 'default'.
imagebitmap.colorSpaceConversionstring'default'Decode using color space conversion. Either 'none' or 'default' default indicates implementation-specific behavior.
imagebitmap.resizeWidthnumber-Output image width.
imagebitmap.resizeHeightnumber-Output image height.
imagebitmap.resizeQualitystring'low'Algorithm to be used for resizing the input to match the output dimensions. One of pixelated, low (default), medium, or high.

Portability note: The exact set of imagebitmap options supported may depend on the browser. Node.js does not implement createImageBitmap() or imagebitmap option handling.

Remarks​

  • In browsers without ImageBitmap support, ImageLoader throws instead of falling back to HTMLImageElement.
  • Under Node.js, the installed ImageBitmap polyfill is intentionally minimal and only supports the functionality needed by ImageLoader and getImageData(image).
  • The SVG path may still use HTMLImageElement internally as a bridge before producing the final ImageBitmap.
  • Node.js support requires import @loaders.gl/core/polyfills before loading images.

Node.js codec setup​

Install sharp explicitly and import @loaders.gl/core/polyfills before loading images under Node.js. The optional backend detects formats from the encoded bytes and wraps RGBA pixels in the minimal Node ImageBitmap polyfill. Browser decoding continues to use native createImageBitmap().

The Node wrapper supports getImageData() and close(). Browser canvas integration, transferability, and ImageBitmapOptions such as resize/crop are not implemented by this wrapper. These options remain browser-dependent.