@eryx/image Module

JSON

Basic operations for reading and writing images.

Summary

Classes

width: number
height: number
channels: number
pixelBuffer: buffer
Image:getPixel(x: number, y: number){ number }
Image:setPixel(x: number, y: number, rgba: { number })()
Image:save(path: string, quality: number?)()
Image:resize(width: number, height: number)Image

Functions

image.open(path: string)Image
image.fromRGBABuffer(pixelData: buffer, width: number, height: number, channels: number)Image

API Reference

Classes

Image

Properties

width: number

The width of the image, in pixels

height: number

The height of the image, in pixels

channels: number

The number of bytes each pixel uses. All images are currently loaded in 4-channel RGBA mode.

pixelBuffer: buffer

The raw buffer of pixel data, arranged in row-major order

Image:getPixel

Read a single pixel from an image

Image:getPixel(x: number, y: number){ number }

Parameters

x: number

The x coordinate. 0-indexed

y: number

The y coordinate. 0-indexed

Returns

{ number }

Tuple of {R, G, B, A}, all in range 0-255

Image:setPixel

Write a single pixel to an image

Image:setPixel(x: number, y: number, rgba: { number })()

Parameters

x: number

The x coordinate. 0-indexed

y: number

The y coordinate. 0-indexed

rgba: { number }

Tuple of {R, G, B, A}, all in range 0-255

Image:save

Save this image to a file. The format is inferred from the filename.

Supported formats:

  • PNG: .png
  • JPEG: .jpg/.jpeg
  • BMP: .bmp
  • TGA: .tga
Image:save(path: string, quality: number?)()

Image:resize

Resize an image.

Downsampling an image uses the Mitchell filter, upsampling uses cubic interpolation.

Image:resize(width: number, height: number)Image

Functions

image.open

Open an image from the filesystem. The format is inferred from the filename.

Supported formats: JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM

image.open(path: string)Image

image.fromRGBABuffer

Load an image from a buffer.

image.fromRGBABuffer(pixelData: buffer, width: number, height: number, channels: number)Image

Parameters

pixelData: buffer

The buffer containing raw pixel data in RGBA format

width: number

The width of the image in pixels

height: number

The height of the image in pixels

channels: number

The number of bytes per pixel. The only legal value for this parameter is 4