- Select ref document -

Image API documentation

version 1.2.162

Functions for creating image objects.

Functions

image.load

image.load(buffer, [premult])

Load image (PNG or JPEG) from buffer.

Parameters

buffer

string image data buffer

[premult]

boolean optional flag if alpha should be premultiplied. Defaults to false

buffer

string image data buffer

[premult]

boolean optional flag if alpha should be premultiplied. Defaults to false

Returns

image

table 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
  • string buffer: the raw image data
image

table 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
  • 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)

Constants

image.TYPE_LUMINANCE

image.TYPE_RGB

image.TYPE_RGBA