Image API documentation

Version: alpha

FUNCTION
image.load() load image from buffer
image.load_buffer() load image from a string into a buffer object
CONSTANT
image.TYPE_RGB RGB image type
image.TYPE_RGBA RGBA image type
image.TYPE_LUMINANCE luminance image type
image.TYPE_LUMINANCE_ALPHA luminance image type

Functions

image.load()

image.load(buffer,[options])

Load image (PNG or JPEG) from buffer.

PARAMETERS

buffer string image data buffer
[options] table An optional table containing parameters for loading the image. Supported entries:
premultiply_alpha
boolean True if alpha should be premultiplied into the color components. Defaults to false.
flip_vertically
boolean True if the image contents should be flipped vertically. Defaults to false.

RETURNS

image table, nil object or nil if loading fails. The object is a table with the following fields:
  • number width: image width
  • number height: image height
  • constant type: image type
    • image.TYPE_RGB
    • image.TYPE_RGBA
    • image.TYPE_LUMINANCE
    • image.TYPE_LUMINANCE_ALPHA
  • string buffer: the raw image data

EXAMPLES

How to load an image from an URL and create a GUI texture from it:
local imgurl = "http://www.site.com/image.png"
http.request(imgurl, "GET", function(self, id, response)
        local img = image.load(response.response)
        local tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer)
    end)

image.load_buffer()

image.load_buffer(buffer,[options])

Load image (PNG or JPEG) from a string buffer.

PARAMETERS

buffer string image data buffer
[options] table An optional table containing parameters for loading the image. Supported entries:
premultiply_alpha
boolean True if alpha should be premultiplied into the color components. Defaults to false.
flip_vertically
boolean True if the image contents should be flipped vertically. Defaults to false.

RETURNS

image table, nil object or nil if loading fails. The object is a table with the following fields:
  • number width: image width
  • number height: image height
  • constant type: image type
    • image.TYPE_RGB
    • image.TYPE_RGBA
    • image.TYPE_LUMINANCE
    • image.TYPE_LUMINANCE_ALPHA
  • buffer buffer: the script buffer that holds the decompressed image data. See buffer.create how to use the buffer.

EXAMPLES

Load an image from an URL as a buffer and create a texture resource from it:
local imgurl = "http://www.site.com/image.png"
http.request(imgurl, "GET", function(self, id, response)
        local img = image.load_buffer(response.response, { flip_vertically = true })
        local tparams = {
            width  = img.width,
            height = img.height,
            type   = resource.TEXTURE_TYPE_2D,
            format = resource.TEXTURE_FORMAT_RGBA }

        local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer)
        -- Apply the texture to a model
        go.set("/go1#model", "texture0", my_texture_id)
    end)

Constants

image.TYPE_RGB

RGB image type


image.TYPE_RGBA

RGBA image type


image.TYPE_LUMINANCE

luminance image type


image.TYPE_LUMINANCE_ALPHA

luminance image type