Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Constructors

constructor

  • new Image(data: any): Image
  • This is for internal use. If you intend on creating a new image, use Image.new instead. If you want to load an image from a URL, use Image.load or Image.loadMultiple.

    property

    {number} width The images width

    property

    {number} height The images height

    Parameters

    • data: any

    Returns Image

Properties

bitmap

bitmap: Uint8ClampedArray

The images RGBA pixel data

Accessors

height

  • get height(): number
  • The images height

    Returns number

width

  • get width(): number
  • The images width

    Returns number

Static RESIZE_AUTO

  • get RESIZE_AUTO(): number
  • Used for automatically preserving an images aspect ratio when resizing.

    Returns number

Static RESIZE_NEAREST_NEIGHBOR

  • get RESIZE_NEAREST_NEIGHBOR(): string

Methods

[Symbol.iterator]

  • [Symbol.iterator](): void
  • Yields an [x,y] array for every pixel in the image

    yields

    {[number, number]} The coordinates of the pixel

    Returns void

averageColor

  • averageColor(): number
  • Gets the average color of the image

    Returns number

blue

  • blue(saturation: number, absolute?: boolean): Image
  • Sets the blue channels saturation

    Parameters

    • saturation: number

      The saturation to apply (0..1)

    • Optional absolute: boolean

      Whether to scale the current saturation (false) or just set the new saturation (true)

    Returns Image

clone

  • Clones the current image

    Returns Image

composite

  • composite(source: Image, x?: number, y?: number): Image
  • Composites (overlays) the source onto this image at the specified coordinates

    Parameters

    • source: Image

      The image to place

    • Optional x: number
    • Optional y: number

    Returns Image

crop

  • crop(x: number, y: number, width: number, height: number): Image
  • Crops an image to the specified dimensions

    Parameters

    • x: number

      The x offset

    • y: number

      The y offset

    • width: number

      The new images width

    • height: number

      The new images height

    Returns Image

cropCircle

  • cropCircle(max?: boolean, feathering?: number): Image
  • Crops the image into a circle

    Parameters

    • Optional max: boolean
    • Optional feathering: number

    Returns Image

detectFaces

  • detectFaces(): Face[]
  • Detects faces in an image

    Returns Face[]

drawBox

  • drawBox(x: number, y: number, width: number, height: number, color: number | ((x: number, y: number) => number)): Image
  • Draws a box at the specified coordinates

    Parameters

    • x: number

      The x offset

    • y: number

      The y offset

    • width: number

      The box width

    • height: number

      The box height

    • color: number | ((x: number, y: number) => number)

      The color to fill the box in with

    Returns Image

drawCircle

  • drawCircle(x: number, y: number, radius: number, color: number | ((x: number, y: number) => number)): Image
  • Draws a circle at the specified coordinates with the specified radius

    Parameters

    • x: number

      The center x position

    • y: number

      The center y position

    • radius: number

      The circles radius

    • color: number | ((x: number, y: number) => number)

    Returns Image

fill

  • fill(color: number | ((x: number, y: number) => number)): Image
  • Fills the image data with the supplied color

    Parameters

    • color: number | ((x: number, y: number) => number)

    Returns Image

getPixelAt

  • getPixelAt(x: number, y: number): number
  • Gets the pixel color at the specified position

    Parameters

    • x: number
    • y: number

    Returns number

    The color value

green

  • green(saturation: number, absolute?: boolean): Image
  • Sets the green channels saturation

    Parameters

    • saturation: number

      The saturation to apply (0..1)

    • Optional absolute: boolean

      Whether to scale the current saturation (false) or just set the new saturation (true)

    Returns Image

hueShift

  • hueShift(degrees: number): Image
  • Shifts the images hue

    Parameters

    • degrees: number

      How many degrees to shift the hue by

    Returns Image

invert

  • Inverts the images colors

    Returns Image

invertHue

  • Inverts the images hue

    Returns Image

invertSaturation

  • invertSaturation(): Image
  • Inverts the images saturation

    Returns Image

invertValue

  • Inverts the images value (lightness)

    Returns Image

iterateWithColors

  • iterateWithColors(): void
  • Yields an [x,y,color] array for every pixel in the image

    yields

    {[number, number, number]} The coordinates and color of the pixel

    Returns void

lightness

  • lightness(value: number, absolute?: boolean): Image
  • Sets the brightness of the image

    Parameters

    • value: number

      The lightness to apply (0..1)

    • Optional absolute: boolean

      Whether to scale the current lightness (false) or just set the new lightness (true)

    Returns Image

opacity

  • opacity(opacity: number, absolute?: boolean): Image
  • Sets the images opacity

    Parameters

    • opacity: number

      The opacity to apply (0..1)

    • Optional absolute: boolean

      Whether to scale the current opacity (false) or just set the new opacity (true)

    Returns Image

red

  • red(saturation: number, absolute?: boolean): Image
  • Sets the red channels saturation

    Parameters

    • saturation: number

      The saturation to apply (0..1)

    • Optional absolute: boolean

      Whether to scale the current saturation (false) or just set the new saturation (true)

    Returns Image

resize

  • resize(width: number, height: number, mode?: string): Image
  • Resizes the image to the given dimensions. Use Image.RESIZE_AUTO as either width or height to automatically preserve the aspect ratio.

    Parameters

    • width: number

      The new width

    • height: number

      The new height

    • Optional mode: string

    Returns Image

    The resized image

rotate

  • rotate(angle: number, resize?: boolean): Image
  • Rotates the image the given amount of degrees

    Parameters

    • angle: number

      The angle to rotate the image for (in degrees)

    • Optional resize: boolean

      Whether to resize the image so it fits all pixels or just ignore outlying pixels

    Returns Image

saturation

  • saturation(value: number, absolute?: boolean): Image
  • Sets the saturation of the image

    Parameters

    • value: number

      The saturation to apply (0..1)

    • Optional absolute: boolean

      Whether to scale the current saturation (false) or just set the new saturation (true)

    Returns Image

scale

  • scale(factor: number, mode?: string): Image
  • Resizes the image by the given factor

    Parameters

    • factor: number

      The factor to resize the image with

    • Optional mode: string

    Returns Image

setPixelAt

  • setPixelAt(x: number, y: number, pixelColor: number): Image
  • Sets the pixel color for the specified position

    Parameters

    • x: number
    • y: number
    • pixelColor: number

    Returns Image

Static colorToRGB

  • colorToRGB(color: number): number[]
  • Converts a color value to an array of RGBA values (ignoring the colors alpha)

    Parameters

    • color: number

      The color value to convert

    Returns number[]

    The RGB values ([R, G, B])

Static colorToRGBA

  • colorToRGBA(color: number): number[]
  • Converts a color value to an array of RGBA values

    Parameters

    • color: number

      The color value to convert

    Returns number[]

    The RGBA values ([R, G, B, A])

Static hslToColor

  • hslToColor(h: number, s: number, l: number): number
  • Converts HSL colors to RGBA colors (assuming an opacity of 255)

    Parameters

    • h: number

      hue (0..1)

    • s: number

      saturation (0..1)

    • l: number

      lightness (0..1)

    Returns number

    color

Static hslaToColor

  • hslaToColor(h: number, s: number, l: number, a: number): number
  • Converts HSLA colors to RGBA colors

    Parameters

    • h: number

      hue (0..1)

    • s: number

      saturation (0..1)

    • l: number

      lightness (0..1)

    • a: number

      opacity (0..1)

    Returns number

    color

Static load

  • load(url: string): Image
  • Loads the given URL as an image. If you need to load multiple images, consider using Image.loadMultiple for increased performance.

    Parameters

    • url: string

      The URL to load

    Returns Image

    The loaded image

Static loadFont

  • loadFont(name: string): string
  • deprecated

    ImageScript now uses a global font cache. Manually caching fonts is no longer required.

    Parameters

    • name: string

    Returns string

Static loadMultiple

  • loadMultiple(urls: string[]): Image[]
  • Loads multiple images simultaneously

    Parameters

    • urls: string[]

      The URLs to load

    Returns Image[]

    The loaded images

Static new

  • new(width: number, height: number, fillColor?: number): Image
  • Creates a new image with the given dimensions

    Parameters

    • width: number
    • height: number
    • Optional fillColor: number

    Returns Image

Static renderText

  • renderText(size: number, color: number, font: string, text: string, wrapWidth?: number): Image
  • Creates a new image containing the rendered text. Currently, sizes other than 128 look pixelated. This is because ImageScript currently only supports nearest neighbor resizing. Smoother resizing will be implemented soon.

    Parameters

    • size: number

      The font size to use (in pixels)

    • color: number

      The color to render the text in

    • font: string

      The font to use. List of available fonts

    • text: string

      The text to render

    • Optional wrapWidth: number

    Returns Image

Static rgbToColor

  • rgbToColor(r: number, g: number, b: number): number
  • Converts RGB components to an RGBA value (assuming alpha = 255)

    Parameters

    • r: number

      red (0..255)

    • g: number

      green (0..255)

    • b: number

      blue (0..255)

    Returns number

    RGBA value

Static rgbaToColor

  • rgbaToColor(r: number, g: number, b: number, a: number): number
  • Converts RGBA components to an RGBA value

    Parameters

    • r: number

      red (0..255)

    • g: number

      green (0..255)

    • b: number

      blue (0..255)

    • a: number

      alpha (0..255)

    Returns number

    RGBA value

Static rgbaToHSLA

  • rgbaToHSLA(r: number, g: number, b: number, a: number): number[]
  • Converts an RGBA value to an array of HSLA values

    Parameters

    • r: number

      (0..255)

    • g: number

      (0..255)

    • b: number

      (0..255)

    • a: number

      (0..255)

    Returns number[]

    The HSLA values ([H, S, L, A])