LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
image

Loading, creating, drawing and saving images. More...

Detailed Description

Every function that takes an image as its first parameter can also be called as a method:

local img = image.load("app0:picture.png")
while true do
img:display(0, 0) -- same as image.display(img, 0, 0)
draw.text(10, 10, img:width().." × "..img:height(), color.new(255, 255, 255))
draw.swapbuffers()
end

Images are freed automatically when they are no longer used (garbage collected).

All the rotating functions take the angle in radians (use math.rad(degrees) to convert) and use the given position as the center of the image.

Functions

image image.load (string path)
 
image image.new (number width, number height, color color)
 
image image.screen ()
 
nil image.display (image image, number x, number y, color tint)
 
nil image.scaledisplay (image image, number x, number y, number scale_x, number scale_y, color tint)
 
nil image.rotatedisplay (image image, number x, number y, number angle, color tint)
 
nil image.scalerotatedisplay (image image, number x, number y, number scale_x, number scale_y, number angle, color tint)
 
nil image.partdisplay (image image, number x, number y, number tex_x, number tex_y, number tex_w, number tex_h, color tint)
 
nil image.scalepartdisplay (image image, number x, number y, number tex_x, number tex_y, number tex_w, number tex_h, number scale_x, number scale_y, color tint)
 
nil image.scalerotatepartdisplay (image image, number x, number y, number tex_x, number tex_y, number tex_w, number tex_h, number scale_x, number scale_y, number angle, color tint)
 
number image.width (image image)
 
number image.height (image image)
 
color image.pixel (image image, number x, number y, color color)
 
nil image.grayscale (image image)
 
nil image.invert (image image)
 
nil image.filter (image image, SceGxmTextureFilter min, SceGxmTextureFilter mag)
 
SceGxmTextureFilter image.min (image image)
 
SceGxmTextureFilter image.mag (image image)
 
nil image.save (image image, string path, string type, number quality)
 
string image.qrscan (image image, number index)
 
image image.qr (table parameters)
 

Texture filters

Used with image.filter(), image.min() and image.mag()

SceGxmTextureFilter SCE_GXM_TEXTURE_FILTER_POINT
 Nearest pixel, keeps the image sharp/pixelated when scaled (good for pixel art)
 
SceGxmTextureFilter SCE_GXM_TEXTURE_FILTER_LINEAR
 Smooths the image when scaled.
 
SceGxmTextureFilter SCE_GXM_TEXTURE_FILTER_MIPMAP_LINEAR
 Linear filtering with mipmaps.
 
SceGxmTextureFilter SCE_GXM_TEXTURE_FILTER_MIPMAP_POINT
 Point filtering with mipmaps.
 

QR code error correction levels

Used in the error_correction field of image.qr(). Higher levels make the QR code bigger, but readable even if partly damaged.

qrcodegen_Ecc qrcodegen_Ecc_LOW
 About 7% of the QR code can be damaged.
 
qrcodegen_Ecc qrcodegen_Ecc_MEDIUM
 About 15% of the QR code can be damaged (default)
 
qrcodegen_Ecc qrcodegen_Ecc_QUARTILE
 About 25% of the QR code can be damaged.
 
qrcodegen_Ecc qrcodegen_Ecc_HIGH
 About 30% of the QR code can be damaged.
 

QR code masks

Used in the mask field of image.qr(). Leave it at automatic unless you need a specific mask pattern.

qrcodegen_Mask qrcodegen_Mask_AUTO
 Picks the best mask automatically (default)
 
qrcodegen_Mask qrcodegen_Mask_0
 Mask pattern 0.
 
qrcodegen_Mask qrcodegen_Mask_1
 Mask pattern 1.
 
qrcodegen_Mask qrcodegen_Mask_2
 Mask pattern 2.
 
qrcodegen_Mask qrcodegen_Mask_3
 Mask pattern 3.
 
qrcodegen_Mask qrcodegen_Mask_4
 Mask pattern 4.
 
qrcodegen_Mask qrcodegen_Mask_5
 Mask pattern 5.
 
qrcodegen_Mask qrcodegen_Mask_6
 Mask pattern 6.
 
qrcodegen_Mask qrcodegen_Mask_7
 Mask pattern 7.
 

QR code versions

Used in the min_version and max_version fields of image.qr(). The version decides the size of the QR code.

number qrcodegen_VERSION_MIN
 Smallest QR code version (1)
 
number qrcodegen_VERSION_MAX
 Biggest QR code version (40)
 

Function Documentation

◆ image.display()

nil image.display ( image image,
number x,
number y,
color tint )

Draws an image

Method form: img:display(x, y, tint)

Parameters
imageThe image
xLeft position
yTop position
tintColor multiplied with the image, e.g. a half transparent white makes the image half transparent (optional)

◆ image.filter()

nil image.filter ( image image,
SceGxmTextureFilter min,
SceGxmTextureFilter mag )

Sets how an image is smoothed when it's drawn scaled

Method form: img:filter(min, mag)

Parameters
imageThe image
minFilter used when the image is drawn smaller, one of the texture filter constants
magFilter used when the image is drawn bigger (optional, default: same as min)
Example:
-- Keep pixel art sharp when scaling it up
sprite:scaledisplay(0, 0, 4, 4)
SceGxmTextureFilter SCE_GXM_TEXTURE_FILTER_POINT
Nearest pixel, keeps the image sharp/pixelated when scaled (good for pixel art)
Definition lj_draw.h:427

◆ image.grayscale()

nil image.grayscale ( image image)

Turns an image into black & white. This changes the image itself.

Method form: img:grayscale()

Parameters
imageThe image

◆ image.height()

number image.height ( image image)

Gets the height of an image

Method form: img:height()

Parameters
imageThe image
Returns
Height in pixels

◆ image.invert()

nil image.invert ( image image)

Inverts the colors of an image (like a photo negative). This changes the image itself, the alpha stays the same.

Method form: img:invert()

Parameters
imageThe image

◆ image.load()

image image.load ( string path)

Loads an image file. Supported formats: .PNG, .JPG/.JPEG, .BMP, .TGA, .PSD, .HDR, .PIC, .PPM/.PGM and .SVG.

Parameters
pathPath to the image (e.g. "app0:bg.png")
Returns
The image, or nil if the file doesn't exist or its format isn't supported
Example:
local bg = image.load("app0:bg.png")
if not bg then error("Couldn't load bg.png") end

◆ image.mag()

SceGxmTextureFilter image.mag ( image image)

Gets the filter used when the image is drawn bigger

Method form: img:mag()

Parameters
imageThe image
Returns
One of the texture filter constants

◆ image.min()

SceGxmTextureFilter image.min ( image image)

Gets the filter used when the image is drawn smaller

Method form: img:min()

Parameters
imageThe image
Returns
One of the texture filter constants

◆ image.new()

image image.new ( number width,
number height,
color color )

Creates a new, empty image

Parameters
widthWidth in pixels
heightHeight in pixels
colorColor to fill the image with (optional, the image is fully transparent if omitted)
Returns
The new image

◆ image.partdisplay()

nil image.partdisplay ( image image,
number x,
number y,
number tex_x,
number tex_y,
number tex_w,
number tex_h,
color tint )

Draws only a part of an image, useful for sprite sheets

Method form: img:partdisplay(x, y, tex_x, tex_y, tex_w, tex_h, tint)

Parameters
imageThe image
xLeft position on the screen
yTop position on the screen
tex_xLeft of the part inside the image
tex_yTop of the part inside the image
tex_wWidth of the part
tex_hHeight of the part
tintColor multiplied with the image (optional)
Example:
-- Draw the 3rd 32 × 32 frame of a sprite sheet
sheet:partdisplay(100, 100, 2 * 32, 0, 32, 32)

◆ image.pixel()

color image.pixel ( image image,
number x,
number y,
color color )

Gets or sets the color of one pixel of an image

Method form: img:pixel(x, y) / img:pixel(x, y, color)

Parameters
imageThe image
xX of the pixel, from 0 to width - 1
yY of the pixel, from 0 to height - 1
colorNew color of the pixel (optional)
Returns
The pixel's color if color is omitted, otherwise nothing
Warning
The position isn't checked, make sure it's inside the image.
Example:
local img = image.new(64, 64, color.new(0, 0, 0))
img:pixel(10, 10, color.new(255, 0, 0)) -- set
print(img:pixel(10, 10):r()) -- get, prints 255

◆ image.qr()

image image.qr ( table parameters)

Generates a QR code image

Parameters
parametersA table with these fields (only text is required):
  • string text: Text stored in the QR code
  • color fg_color: Color of the dark squares (default: black)
  • color bg_color: Background color (default: white)
  • number scale: Size of each square in pixels (default: 4)
  • number border: Empty space around the code, in squares (default: 2)
  • number error_correction: One of the QR error correction constants (default: qrcodegen_Ecc_MEDIUM)
  • number min_version, max_version: Allowed QR versions (default: qrcodegen_VERSION_MIN to qrcodegen_VERSION_MAX)
  • number mask: One of the QR mask constants (default: qrcodegen_Mask_AUTO)
  • boolean boostEcl: Use a higher error correction level if it fits in the same size (default: true)
Returns
The QR code image. Raises an error if the text is too long to fit.
Example:
local qr = image.qr({text = "https://github.com/HarommelRabbid/LifeLua", scale = 6})
while true do
qr:display(480 - qr:width() / 2, 272 - qr:height() / 2)
draw.swapbuffers()
end

◆ image.qrscan()

string image.qrscan ( image image,
number index )

Looks for a QR code in an image and reads it

Method form: img:qrscan(index)

Parameters
imageThe image
indexWhich QR code to read if there are several, starting at 0 (optional, default: 0)
Returns
The text inside the QR code, or nil if no readable QR code was found
See also
camera.output() to get camera frames as images, for scanning QR codes live

◆ image.rotatedisplay()

nil image.rotatedisplay ( image image,
number x,
number y,
number angle,
color tint )

Draws a rotated image

Method form: img:rotatedisplay(x, y, angle, tint)

Parameters
imageThe image
xX position of the image's center
yY position of the image's center
angleRotation in radians
tintColor multiplied with the image (optional)

◆ image.save()

nil image.save ( image image,
string path,
string type,
number quality )

Saves an image to a file

Method form: img:save(path, type, quality)

Parameters
imageThe image
pathWhere to save it (e.g. "ux0:data/picture.png")
typeFile type (optional, default: "png"), one of:
  • "png"
  • "jpg" / "jpeg"
  • "bmp"
  • "tga"
  • "hdr"
qualityJPEG quality from 1 to 100, only used for "jpg"/"jpeg" (optional, default: 100)
Example:
local shot = image.screen()
shot:save("ux0:data/screenshot.jpg", "jpg", 90)

◆ image.scaledisplay()

nil image.scaledisplay ( image image,
number x,
number y,
number scale_x,
number scale_y,
color tint )

Draws a scaled image

Method form: img:scaledisplay(x, y, scale_x, scale_y, tint)

Parameters
imageThe image
xLeft position
yTop position
scale_xHorizontal scale, 1 is the original size, 2 is twice as wide, -1 flips the image
scale_yVertical scale, 1 is the original size, 2 is twice as tall, -1 flips the image
tintColor multiplied with the image (optional)

◆ image.scalepartdisplay()

nil image.scalepartdisplay ( image image,
number x,
number y,
number tex_x,
number tex_y,
number tex_w,
number tex_h,
number scale_x,
number scale_y,
color tint )

Draws a scaled part of an image

Method form: img:scalepartdisplay(x, y, tex_x, tex_y, tex_w, tex_h, scale_x, scale_y, tint)

Parameters
imageThe image
xLeft position on the screen
yTop position on the screen
tex_xLeft of the part inside the image
tex_yTop of the part inside the image
tex_wWidth of the part
tex_hHeight of the part
scale_xHorizontal scale, 1 is the original size
scale_yVertical scale, 1 is the original size
tintColor multiplied with the image (optional)

◆ image.scalerotatedisplay()

nil image.scalerotatedisplay ( image image,
number x,
number y,
number scale_x,
number scale_y,
number angle,
color tint )

Draws a scaled and rotated image

Method form: img:scalerotatedisplay(x, y, scale_x, scale_y, angle, tint)

Parameters
imageThe image
xX position of the image's center
yY position of the image's center
scale_xHorizontal scale, 1 is the original size
scale_yVertical scale, 1 is the original size
angleRotation in radians
tintColor multiplied with the image (optional)

◆ image.scalerotatepartdisplay()

nil image.scalerotatepartdisplay ( image image,
number x,
number y,
number tex_x,
number tex_y,
number tex_w,
number tex_h,
number scale_x,
number scale_y,
number angle,
color tint )

Draws a scaled and rotated part of an image

Method form: img:scalerotatepartdisplay(x, y, tex_x, tex_y, tex_w, tex_h, scale_x, scale_y, angle, tint)

Parameters
imageThe image
xX position of the part's center on the screen
yY position of the part's center on the screen
tex_xLeft of the part inside the image
tex_yTop of the part inside the image
tex_wWidth of the part
tex_hHeight of the part
scale_xHorizontal scale, 1 is the original size
scale_yVertical scale, 1 is the original size
angleRotation in radians
tintColor multiplied with the image (optional)

◆ image.screen()

image image.screen ( )

Takes a screenshot of the screen as an image (960 × 544)

Returns
The new image

◆ image.width()

number image.width ( image image)

Gets the width of an image

Method form: img:width()

Parameters
imageThe image
Returns
Width in pixels