Dev - Lua Libraries

Lua Command: s3sprite.getUnloadedImageSize

Parameters

Return Values

Signature

int width, int height = s3sprite.getUnloadedImageSize(string imagePath)

Description

Gets the width and height of the image with the the given imagePath in pixels. The image does not have to be loaded to make this work.

imagePath must be relative to the folder of the current mod and point to a JPG/JPEG, PNG, BMP or GIF file.

width and height will both be 0 if the given image does not exist or if it was not possible to detect the size.

Example:

Print the width and height of an image without loading it
1
2
w, h = s3sprite.getUnloadedImageSize("interface/cursor.png")
print("The image has a size of " .. w .. " x " .. h .. "pixels!")

Note:

Use s3sprite.getImageSize if the image has been loaded already. It is much faster.

Note:

Use s3sprite.getSize if you want to get the size of a sprite instance.

Warning:

This command reads the file header to determine the image size. This can be slow. Do not call this command frequently/in loops. Save the result in variables instead of calling this command multiple times for the same file!