Lua Image Library

A comfortable image library for Lua

General API

local lil = require("lil")

lil.open("img.png"):invert():save("inverted.png", { speed = 1.0 })

local font = lil.font("sans:italic:lang=is", "fff", 100)
local img = font:text("Vertu sæll og blessaður!")
img:expand(100):bg("000")
img:save("sæll.png")

Colours can be either a table of normalised floats { r, g, b[, a] } or a hex string RGB, RGBA, RRGGBB, or RRGGBBAA with an optional # prefix

Coordinates are in X,Y order and start at 0 instead of the usual 1 in Lua

Documentation is available at sylvie.moe/lil or can be generated using make docs

Examples are in doc/examples/

Installing with Luarocks

Install: luarocks install lil —lua-version=5.X

Link: luarocks.org/modules/nazrin/lil

Building

There are no hard dependencies other than Lua 5.1+, GNU Make or Luarocks, and a (sanely modern) C99 compiler

Optional dependencies are OpenMP and the libraries listed below

Required for the default configuration: Ubuntu/Mint/etc apt install libpng-dev libgif-dev libfontconfig-dev libturbojpeg-dev libwebp-dev libfreetype-dev libluajit-5.1-dev Arch: sudo pacman -S giflib fontconfig libjpeg-turbo libwebp freetype2 luajit libpng

Luarocks

  • luarocks make

GNU Make

  • Edit config.mk if you want
  • make or make amgl

Supported formats

Import/Export

  • png (libpng)
  • jpeg (libjpeg-turbo)
  • webp (libwebp)
  • farbfeld (custom)

Import

  • gif (giflib)
  • text rendering (libfreetype2, libfontconfig)

Extending

See src/img.h for C extensions

lil.ctxMT and lil.imgMT can be added to for adding methods either from C or Lua

Adding handlers

Handlers are stored in lil.formatHandlers, to extend it you can add an entry with the id (name) of the format as the index

An example that reads farbfeld files compressed with bzip2 is in doc/examples/lil-ffbz2.lua

lil.formatHandlers.png = {
    import     = function(data) … return Img end,
    export     = function(Img) … return data end,
    pattern    = "^\x89PNG\x0d\x0a\x1a\x0a",
    extensions = { '%.png$' }
}
generated by LDoc 1.4.6 Last updated 2023-04-13 13:58:34