Skip to content

Image

The Image class enables loading images from files and rendering them onto the screen.


Synopsis

Constructors

Static Methods

Static Members

Instance Methods


Constructors

Image(path)

Loads an image from given path.

Parameters:

Parameter Type Required Description
path string Yes The path of the image to load.

Static Methods

Image.create(width, height)

Creates a completely blank, mutable RGBA image of the specified dimensions.

Parameters:

Parameter Type Required Description
width int Yes Width of the image.
height int Yes Height of the image.

Image.create_render_target(width, height)

Creates a blank RGBA image that is capable of being targeted for custom runtime drawing operations.

Parameters:

Parameter Type Required Description
width int Yes Width of the image.
height int Yes Height of the image.

Static Members

Image.BlendAdd

  • Type: int

Additive blending mode, useful for lighting or particle effects.

Image.BlendDestinationOut

  • Type: int

Destination-out blending mode, typically used for masking out elements.

Image.BlendMultiply

  • Type: int

Multiplies the source colors with the destination colors.

Image.BlendNormal

  • Type: int

Standard alpha blending (Default).

Image.BlendPremultiplied

  • Type: int

Blending mode designed for assets utilizing premultiplied alpha channels.


Instance Methods

image.draw(x, y[, options])

Render the image at given coordinates with specified options.

Draw Options Table

Field Type Default Description
src table null Source rectangle within the image { x, y, w, h } format. Defaults to the entire image.
size table null Target destination size in { w, h } format. Overrides separate width/height properties.
w | width float Original Width Explicit target width for scaling.
h | height float Original Height Explicit target height for scaling.
scale float|table 1.0 Scale factors formatted as either a single float (uniform scale) or a table in { x, y } format.
angle float 0.0 Rotation angle specified in degrees.
origin table null Anchor origin point for rotation/scaling in { x, y } format. Defaults to top-left (0,0), or the image center if centered is true.
centered bool false When set to true (and origin isn't explicitly defined), it centers the draw origin point automatically based on final dimensions.
color table null RGB tint color with optional alpha transparency, in { r, g, b, a } format, using ranges 0 to 255.
alpha float 1.0 Opacity from 0.0 (invisible) to 1.0 (opaque).
blend int Image.BlendNormal The blend mode to use.
flip_x bool false Flips the rendered asset horizontally if true.
flip_y bool false Flips the rendered asset vertically if true.

image.height()

Get the image height.

  • Returns: int: The image height.

image.hit_test(x, y)

Perform a hit test against the image's alpha channel at given coordinates.

Parameters:

Parameter Type Required Description
x int Yes X coordinate.
y int Yes Y coordinate.
  • Returns: bool: true if the image's pixel at (x, y) has non-zero alpha. false otherwise.

image.size()

Get image size as a table.

  • Returns: table

Size Table

Field Type Description
width int The image width.
height int The image height.

image.width()

Get the image width.

  • Returns: int: The image width.