Namespace: image
Language: Lua
Type: Defold Lua
File: script_image.cpp
Source: engine/gamesys/src/gamesys/scripts/script_image.cpp
Functions for creating image objects.
Type: FUNCTION get the header of an .astc buffer
Parameters
buffer (string) - .astc file data bufferReturns
table (table |
nil) - header or nil if buffer is not a valid .astc. The header has these fields: |
width: image widthheight: image heightdepth: image depthblock_size_x: block size xblock_size_y: block size yblock_size_z: block size zExamples
How to get the block size and dimensions from a .astc file
local s = sys.load_resource("/assets/cat.astc")
local header = image.get_astc_header(s)
pprint(s)
Type: FUNCTION Load image (PNG or JPEG) from buffer.
Parameters
buffer (string) - image data bufferoptions (table) (optional) - An optional table containing parameters for loading the image. Supported entries:premultiply_alphaboolean True if alpha should be premultiplied into the color components. Defaults to false.</dd>
flip_verticallyboolean True if the image contents should be flipped vertically. Defaults to false.</dd>
</dl>
Returns
image (table |
nil) - object or nil if loading fails. The object is a table with the following fields: |
width: image widthheight: image heighttype: image typeimage.TYPE_RGBimage.TYPE_RGBAimage.TYPE_LUMINANCEimage.TYPE_LUMINANCE_ALPHAbuffer: the raw image dataExamples
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)
Type: FUNCTION Load image (PNG or JPEG) from a string buffer.
Parameters
buffer (string) - image data bufferoptions (table) (optional) - An optional table containing parameters for loading the image. Supported entries:premultiply_alphaboolean True if alpha should be premultiplied into the color components. Defaults to false.</dd>
flip_verticallyboolean True if the image contents should be flipped vertically. Defaults to false.</dd>
</dl>
Returns
image (table |
nil) - object or nil if loading fails. The object is a table with the following fields: |
width: image widthheight: image heighttype: image typeimage.TYPE_RGBimage.TYPE_RGBAimage.TYPE_LUMINANCEimage.TYPE_LUMINANCE_ALPHAbuffer: 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 = graphics.TEXTURE_TYPE_2D,
format = graphics.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)
Type: CONSTANT luminance image type
Type: CONSTANT luminance image type
Type: CONSTANT RGB image type
Type: CONSTANT RGBA image type