- High-performance PNG encoder written in pure Lua with optional LuaJIT FFI backend.
LuaJIT is much faster and Lua is not recommended for production usage.
- Provides a lightweight raster pipeline (geometry, shapes).
- Supports RGB and RGBA color modes.
- Only requires
bitlibrary. - This library does not perform any compression. Output files are uncompressed PNGs.
- Check
examplesfolder for more examples.
luaPNGselects the default runner based on(require("luaPNG.init")).UsingJITvariable.
--- Encoding standart PNG.
local Image = require("luaPNG.init")
local png = Image.new(256, 256, "rgb")
for i = 1, 256*256*3 do
png.Data[i] = math.random(0,255)
end
print(Image.UsingJIT)
png:save("Example256x256.png")
print("Done in: ", os.clock())
--- Encoding standart PNG and drawing rectangle.
local Image = require("luaPNG.init")
local img = Image.new(800, 600, "rgba")
img:add(Geometry.Rectangle{
x = 0, y = 0,
w = 300, h = 300,
color = {220, 60, 60, 180}, -- RGBA
mode = "fill"
})
img:save("Example800x600.png")
print("Done in:", os.clock())- You can run
benchmark/pure_lua_benchmark.luaandbenchmark/ffipng_benchmark.luafiles to run the benchmark.
It will give CSV file in
benchmark/output/*folder.
png.luaslows down or crashes when encoding large RGBA images.
- MIT License