Skip to content

GImage extends GObject

A graphical representation of an image.

Factory Functions

function GImage(source[, x=0, y=0])
Constructs a GImage object from the given source. x and y may be specified to set where the GImage should appear in the window; otherwise, it defaults to (0, 0).
source may be a Data URL, a local file, or a 2D array of pixels.

Note

The GImage is loaded asynchronously, meaning that your code will continue to run while the GImage is loading. However, before it's loaded, it does not know its own width or height. If you need to work with these values, it's recommended to add a "load" event listener.

Methods

function GImage::addEventListener(eventType, listener)
Adds the given listener to this image. The only valid eventType is "load" — any other event type will fail silently.
The load event triggers when the image has been fully loaded.
function GImage::getPixelArray()
Returns: A 2D array of RGBA pixels. You can get the individual color values from these pixels using the methods below.
static function GImage.getAlpha(pixel)
Returns: The alpha value of the given pixel.
static function GImage.getRed(pixel)
Returns: The red intensity of the given pixel.
static function GImage.getGreen(pixel)
Returns: The green intensity of the given pixel.
static function GImage.getBlue(pixel)
Returns: The blue intensity of the given pixel.
static function GImage.createRGBPixel(red, green, blue[, alpha=255])
Returns: A pixel created from the given red, green, blue, and alpha values. If alpha is omitted, defaults to 255 (completely opaque).

Warning

The functions below will all throw an error if this object has been transformed by GObject::rotate, GObject::scale, GObject::shear, or GObject::translate.

function GImage::setSize(object)
Sets this GImage's width/height to match that of the passed-in object of type GDimension, GRectangle, or GObject.
function GImage::setSize(width, height)
Sets this GImage's width and height as specified.
function GImage::setBounds(object)
Sets this GImage's x/y/width/height to match that of the passed-in object of type GRectangle or GObject.
function GImage::setBounds(positionObject, sizeObject)
Sets this GImage's x/y to match that of the passed-in positionObject, and its width/height to match that of the passed-in sizeObject. These objects should be of type GRectangle or GObject. Additionally, positionObject can be a GPoint, and positionObject can be a GDimension.
function GImage::setBounds(x, y, width, height)
Sets this GImage's x, y, width, and height as specified.