A comfortable image library for Lua
Find a file
2025-05-30 05:51:31 +02:00
doc API change: lil: is now lil. and a few small changes/fixes 2022-08-29 14:50:38 +00:00
rel Try again 2023-09-10 15:39:49 +00:00
src Changed spaces to tabs because nazrin is a soy 2025-05-29 20:40:37 -07:00
.ccls Set commit date and hash as _VERSION 2023-12-11 07:51:16 +00:00
.gitignore Made it so the auxiliary library is compiled into lil.so instead of using require("lil-aux"). Made Luarocks use make and generally improved the build system 2023-09-06 21:56:11 +00:00
config.def.mk Added QOI image format. Fixed default config formats 2023-12-08 01:39:01 +00:00
LICENSE LICENSE 2022-08-11 09:23:13 +00:00
lil-aux.lua Changed code to be compilable as C++; Fixed all g++/clang++ warnings; Fixed all cppcheck warnings; Fixed 2 memleaks; More minor code improvements; Added license headers 2023-10-11 02:25:23 +00:00
makefile Remove amgl 2024-03-26 13:44:12 +00:00
readme.md Added QOI image format. Fixed default config formats 2023-12-08 01:39:01 +00:00
txt2h.lua Changed code to be compilable as C++; Fixed all g++/clang++ warnings; Fixed all cppcheck warnings; Fixed 2 memleaks; More minor code improvements; Added license headers 2023-10-11 02:25:23 +00:00
ut.lua Added QOI image format. Fixed default config formats 2023-12-08 01:39:01 +00:00

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 nazrin.codeberg.page/lil/@pages/doc/html/ or can be generated using make docs

Examples are in doc/examples/

Installing with Luarocks

Install: luarocks install lil --lua-version=5.X [CC=clang]

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

GCC seems to have issues when OpenMP is enabled. The default configuration disables multithreading unless using clang: CC=clang

Required for the default configuration:

  • Arch derived: pacman -S giflib fontconfig libjpeg-turbo libwebp freetype2 luajit libpng libavif
  • Debian derived apt install libpng-dev libgif-dev libfontconfig-dev libturbojpeg-dev libwebp-dev libfreetype-dev libavif-dev libluajit-5.1-dev

GNU Make

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

Supported formats

Import/Export

  • avif (libavif or libheif)
  • farbfeld (custom)
  • heif (libheif)
  • jpeg (libjpeg-turbo)
  • png (libpng)
  • qoi (custom)
  • webp (libwebp)

Import

  • gif (giflib)
  • text rastering (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$' }
}