RawImage"},{"local":"rawimagergb-coderawimagecode","title":"`rawImage.rgb()` ⇒ RawImage"},{"local":"rawimagergba-coderawimagecode","title":"`rawImage.rgba()` ⇒ RawImage"},{"local":"rawimageresizewidth-height-options-codepromiseampltrawimageampgtcode","title":"`rawImage.resize(width, height, options)` ⇒ Promise.<RawImage>"},{"local":"rawimageupdatedata-width-height-channels","title":"`rawImage._update(data, width, height, channels)`"},{"local":"rawimageclone-coderawimagecode","title":"`rawImage.clone()` ⇒ RawImage"},{"local":"rawimageconvertnumchannels-coderawimagecode","title":"`rawImage.convert(numChannels)` ⇒ RawImage"},{"local":"rawimagesavepath","title":"`rawImage.save(path)`"},{"local":"rawimagereadinput-codecode","title":"`RawImage.read(input)` ⇒ *"},{"local":"rawimagefromurlurl-codepromiseampltrawimageampgtcode","title":"`RawImage.fromURL(url)` ⇒ Promise.<RawImage>"},{"local":"rawimagefromblobblob-codepromiseampltrawimageampgtcode","title":"`RawImage.fromBlob(blob)` ⇒ Promise.<RawImage>"}],"title":"utils/image.RawImage"}],"title":"utils/image"}">

utils/image

Helper module for image processing.

These functions and classes are only used internally, meaning an end-user shouldn’t need to access anything here.


utils/image.RawImage

Kind: static class of utils/image


new RawImage(data, width, height, channels)

Create a new RawImage object.

ParamTypeDescription
dataUint8ClampedArray

The pixel data.

widthnumber

The width of the image.

heightnumber

The height of the image.

channels1 | 2 | 3 | 4

The number of channels.


rawImage._CONTENT_TYPE_MAP

Mapping from file extensions to MIME types.

Kind: instance property of RawImage


rawImage.grayscale()RawImage

Convert the image to grayscale format.

Kind: instance method of RawImage
Returns: RawImage - this to support chaining.


rawImage.rgb()RawImage

Convert the image to RGB format.

Kind: instance method of RawImage
Returns: RawImage - this to support chaining.


rawImage.rgba()RawImage

Convert the image to RGBA format.

Kind: instance method of RawImage
Returns: RawImage - this to support chaining.


rawImage.resize(width, height, options)Promise.<RawImage>

Resize the image to the given dimensions. This method uses the canvas API to perform the resizing.

Kind: instance method of RawImage
Returns: Promise.<RawImage> - this to support chaining.

ParamTypeDescription
widthnumber

The width of the new image.

heightnumber

The height of the new image.

optionsObject

Additional options for resizing.

[options.resample]0 | 1 | 2 | 3 | 4 | 5 | string

The resampling method to use.


rawImage._update(data, width, height, channels)

Helper method to update the image data.

Kind: instance method of RawImage

ParamTypeDefaultDescription
dataUint8ClampedArray

The new image data.

widthnumber

The new width of the image.

heightnumber

The new height of the image.

channels1 | 2 | 3 | 4

The new number of channels of the image.


rawImage.clone()RawImage

Clone the image

Kind: instance method of RawImage
Returns: RawImage - The cloned image


rawImage.convert(numChannels)RawImage

Helper method for converting image to have a certain number of channels

Kind: instance method of RawImage
Returns: RawImage - this to support chaining.

ParamTypeDescription
numChannelsnumber

The number of channels. Must be 1, 3, or 4.


rawImage.save(path)

Save the image to the given path.

Kind: instance method of RawImage

ParamTypeDescription
pathstring

The path to save the image to.


RawImage.read(input)*

Helper method for reading an image from a variety of input types.

Kind: static method of RawImage
Returns: * - The image object.

Example: Read image from a URL.

let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
// test 
ParamType
inputRawImage | string | URL

RawImage.fromURL(url)Promise.<RawImage>

Read an image from a URL or file path.

Kind: static method of RawImage
Returns: Promise.<RawImage> - The image object.

ParamTypeDescription
urlstring | URL

The URL or file path to read the image from.


RawImage.fromBlob(blob)Promise.<RawImage>

Helper method to create a new Image from a blob.

Kind: static method of RawImage
Returns: Promise.<RawImage> - The image object.

ParamTypeDescription
blobBlob

The blob to read the image from.