Skip to main content

Loader category

Images in a shape your application can use.

Image loaders hide browser-specific decoding details and expose predictable pixel data, dimensions, and image metadata. Choose an ImageBitmap when a renderer can use it directly, or a decoded image object when you need the pixels.

Category data

Load many formats into one application path.

Category data lets related loaders return compatible structures, so rendering, analysis, and export code can be shared.

What comes back

Decode once, then hand the pixels to the next layer.

The category separates ordinary raster images from GPU texture containers. That keeps image decoding useful for maps, previews, analysis, and rendering without forcing one runtime representation.

Browser path

ImageBitmap for direct rendering

Portable path

Decoded image data with typed pixels

Formats

PNG, JPEG, WebP, GIF, and other browser-supported inputs

Node.js

Use @loaders.gl/core/polyfills for image decoding support

The image loader category documents common data formats, options, conventions, and utilities for loaders and writers that work with raster images under loaders.gl conventions.

Detailed guide

Image decoding details

The sections below cover loader selection, return shapes, browser and Node.js behavior, and writer conventions.

Image Category Loaders​

LoaderNotes
ImageLoaderLoads raster images as ImageBitmap
ImageLoaderDeprecated compatibility image loader
ImageWriterEncodes raster image data to binary formats

Core image category support is provided by the @loaders.gl/images module:

Usage​

The preferred loader for new code is ImageLoader:

import '@loaders.gl/core/polyfills'; // Only required if loading images under Node.js
import {ImageLoader} from '@loaders.gl/images/image';
import {registerLoaders, load} from '@loaders.gl/core';
registerLoaders(ImageLoader);
const image = await load('image.jpeg');

If application code needs raw pixels, convert the loaded image explicitly:

import '@loaders.gl/core/polyfills'; // Only required if loading images under Node.js
import {load} from '@loaders.gl/core';
import {ImageLoader} from '@loaders.gl/images/image';
import {getImageData} from '@loaders.gl/images/api';

const image = await load('image.jpeg', ImageLoader);
const imageData = getImageData(image);

Image Types​

Images can be represented either as opaque image objects (ImageBitmap or Image) or as image data objects.

A loaded image can always be converted to an image data object (an object containing a Uint8Array with the pixel data, and metadata like width and height).

ImageLoader returns ImageBitmap in browsers. Under Node.js with @loaders.gl/core/polyfills, ImageLoader returns a minimal ImageBitmap polyfill backed by decoded image data. Deprecated ImageLoader preserves older compatibility return types and options.

Note that type is independent of the format of the image (see below).

Image TypeClassAvailabilityWorkersDescription
dataObject with {width: Number, height: Number, data: Uint8Array, ...}Node.js and browsers❌ NoCompatible with headless GL and still supported by helper APIs.
imagebitmapImageBitmapBrowser, Node.js⚠️ Browser onlyThe preferred type returned by ImageLoader. Browsers use the native API, while Node.js uses the installed polyfill.
imageImage (aka HTMLImageElement)All browsers❌ NoThe traditional DOM image class. It remains supported by helper APIs and by deprecated ImageLoader.

Image Data​

Image data objects are images represented by an object that contains a typed array with the pixel data, size, and possibly additional metadata {width: Number, height: Number, data: Uint8Array, ...}.

To get an image data object from a loaded Image or ImageBitmap, call getImageData(image).

Image Formats​

The format of the image describes how the memory is laid out. It is mainly important when working with data type images. The default format / memory layout for image data is RGBA and UNSIGNED_BYTE, i.e. four components per pixel, each a byte.

Some loaders may add additional fields to the image data structure to describe the data format. Currently the image category does not provide any documentation for how to describe alternate formats/memory layouts, however a preliminary recommendation is to follow OpenGL/WebGL conventions.

Options​

The image category supports some generic options (specified using options.image.<option-name>), that are applicable to image loaders.

OptionDefaultTypeAvailabilityDescription
options.image.typeunsetstringImageLoader, deprecated ImageLoaderImageLoader only accepts imagebitmap. Deprecated ImageLoader preserves legacy modes.

Notes​

About worker loading​

Worker loading is primarily tied to ImageBitmap support in the current runtime. Deprecated ImageLoader may still use compatibility fallbacks, while ImageLoader always targets bitmap output. Use options.core.worker: false to disable worker loading of images.

About texture loaders​

Compressed GPU texture containers and texture-level return shapes are documented separately in Texture Loaders.

Image API​

The image category also provides a few utilities:

  • Detecting ("sniffing") mime type and size of image files before parsing them
  • Getting image data (arrays of pixels) from an image without knowing which type was loaded with getImageData

Remarks​

ImageData​

Image data objects returned by image category loaders have the same fields (width, height, data) as the browser's built-in ImageData class, but are not actual instances of ImageData. However, should you need it, it is easy to create an ImageData instance from an image data object:

const image = await load(url, ImageLoader);
const data = getImageData(image);
const imageData = new ImageData(data.data, data.width, data.height);