Module Lil

Info:

  • License: MPL-2.0
  • Author: eiko

Functions

findFontPath(FontConfig)
font(nameOrPath, col, w[, h=w]) Creates a new font
hsv2rgb(h, s, v[, a=1])
import(data)
new(w[, h=w]) Creates a blank image
open(path)
parseColour(colour)
rgb2hsv(colour)

Tables

Enums Not an actual table in the library, just documenting them

Class Img

Img:__eq() == equality check, alpha aware
Img:__tostring() Example: lil.Img (707x1000 [test/beer.jpg] 0x0151c880)
Img:clone()
Img:comp(top[, x=0[, y=0[, opts={}]]]) Composites the given image on top
Img:crop(x, y, w, h)
Img:export(format[, opts={}])
Img:getPixel(x, y) Returns the pixel at x,y or nil if its out of range
Img:isOpaque()
Img:new([colour=transparent]) Creates a new blank image with the same dimensions
Img:overwriteInternals(img) Swaps the internal structures with a new image.
Img:resize(w[, h=w[, opts={}]])
Img:rotate(degrees)
Img:save(path[, opts={}])
Img:setPixel(r, g, b, a, x, y) Sets a pixel at x,y.

Img:affine(mat) Applies an affine matrix
Img:bg(colour) Composites the image on top of a colour
Img:blur(x[, y=x[, opts={}]])
Img:brightness(amount)
Img:bw([threshold=0.5])
Img:circle(colour, x, y, w, h[, opts={}])
Img:contrast(amount)
Img:expand(a[, b[, c[, d[, colour=transparent]]]]) Expands the sides of the image.
Img:fg(colour) Overlays the colour on top of the image
Img:fill(colour) Fills the entire image with a single colour
Img:flip(Flag) Flips the image horizontally and/or vertically, by default just vertically
Img:gamma(amount)
Img:grey()
Img:hue(hue)
Img:invert(stringOrInt) By default inverts rgb
Img:kernel(kernel[, opts={}]) Convolution kernel
Img:line(colour, x1, y1, x2, y2[, opts={}])
Img:map(strOrFunc) Runs a function over every pixel in the image.
Img:mirror() Flips horizontally
Img:palette(colours[, opts={}])
Img:poly(colour, points[, opts={}]) Polygon
Img:rect(colour, x, y, w, h[, opts={}])
Img:saturation(saturation) Changes the saturation.
Img:text(font, text[, x=0[, y=0[, opts={}]]]) Writes text to the image
Img:trim([threshold=0[, colour=transparent]]) Trim edges.

Class Text

Font:colour(colour) Sets font colour
Font:getColour() Gets font colour
Font:getSize() Gets font size
Font:measure(text) Returns calculated width and height of text
Font:size(w[, y=w]) Sets font size
Font:text(text[, opts={}]) Creates an image containing just text


Functions

findFontPath(FontConfig) line 75

Parameters:

  • FontConfig string match string

Returns:

    string path
font(nameOrPath, col, w[, h=w]) line 36
Creates a new font

Parameters:

  • nameOrPath string If the string includes a directory seperator (Linux/*BSD/Mac: /, Windows: \) it’s a path to a font file, otherwise it’s a FontConfig match string
  • col colour
  • w int
  • h int (default w)

Returns:

    Font

Usage:

  • font("sans", "fff", 20)
  • font("DejaVuSans:bold", { 0, 0, 0, 1 }, 100)
  • font("monospace:italic", "ff00fa", 25)
  • font("serif:lang=ru:weight=bold", "00ff00fa", 95)
  • font("/usr/share/fonts/TTF/DejaVuSans.ttf", "00ff00fa", 95)
hsv2rgb(h, s, v[, a=1]) line 148

Parameters:

  • h float
  • s float
  • v float
  • a float (default 1)

Returns:

    r, g, b, a
import(data) line 31

Parameters:

  • data string

Returns:

    Img
new(w[, h=w]) line 12
Creates a blank image

Parameters:

  • w int
  • h int (default w)

Returns:

    Img
open(path) line 40

Parameters:

  • path string

Returns:

    Img
parseColour(colour) line 123

Parameters:

Returns:

    r, g, b, a
rgb2hsv(colour) line 133

Parameters:

Returns:

    h, s, v, a

Tables

Enums line 91
Not an actual table in the library, just documenting them

Fields:

  • BlendMode string alpha replace

    add multiply subtract

    lighten darken

    screen dissolve difference

    xor and or

  • SampleMode string nearest bilinear box

    By default upscaling uses bilinear and downscaling uses box. It can be passed as a string or table like { upMode, downMode }

Class Img

Props: int w, int h, lil_Image** ud, [string path]
Img:__eq() line 300
== equality check, alpha aware

Returns:

    bool
Img:__tostring() line 285
Example: lil.Img (707x1000 [test/beer.jpg] 0x0151c880)

Returns:

    string
Img:clone() line 207

Returns:

    Img
Img:comp(top[, x=0[, y=0[, opts={}]]]) line 225
Composites the given image on top

Parameters:

  • top Img
  • x int Bottom X, Where on the bottom image the top gets placed (default 0)
  • y int Bottom Y (default 0)
  • opts
    • crop tab { x, y, w, h }
    • blend string

See also:

Img:crop(x, y, w, h) line 132

Parameters:

  • x int
  • y int
  • w int
  • h int
Img:export(format[, opts={}]) line 73

Parameters:

  • format string
  • opts
    • quality float (default 1.0)
    • speed float (default 0.8)

Returns:

    string
Img:getPixel(x, y) line 165
Returns the pixel at x,y or nil if its out of range

Parameters:

  • x int
  • y int

Returns:

  1. r, g, b, a
  2. nil
Img:isOpaque() line 321

Returns:

    bool
Img:new([colour=transparent]) line 82
Creates a new blank image with the same dimensions

Parameters:

  • colour colour (default transparent)

Returns:

    img
Img:overwriteInternals(img) line 91
Swaps the internal structures with a new image. Used when a method has to create a new lil_Image to replace the current one. Anything that resizes the image or has to keep the full image intact while processing can create new blank template with img:new or lil:new and then swap the internals, after which the old ud gets garbage collected by Lua

Parameters:

  • img

Returns:

    nil
Img:resize(w[, h=w[, opts={}]]) line 99

Parameters:

  • w int
  • h int (default w)
  • opts
    • sample string (default "bilinear"|"box")

See also:

Img:rotate(degrees) line 254

Parameters:

  • degrees float
Img:save(path[, opts={}]) line 58

Parameters:

  • path string
  • opts
    • quality float (default 1.0)
    • speed float (default 0.8)
Img:setPixel(r, g, b, a, x, y) line 189
Sets a pixel at x,y. Does not return the Img since it’s a bit more speed optimised and niche, the sort of thing you use in a loop instead of chaining

Parameters:

  • r float
  • g float
  • b float
  • a float
  • x int
  • y int

Img:affine(mat) line 668
Applies an affine matrix

Parameters:

  • mat tab 3x2 Matrix
Img:bg(colour) line 106
Composites the image on top of a colour

Parameters:

Img:blur(x[, y=x[, opts={}]]) line 318

Parameters:

  • x int
  • y int (default x)
  • opts
    • method string box snn gaussian (default "box")
    • sigma float (default 1)
Img:brightness(amount) line 85

Parameters:

  • amount float -1 to 1
Img:bw([threshold=0.5]) line 58

Parameters:

  • threshold float (default 0.5)
Img:circle(colour, x, y, w, h[, opts={}]) line 103

Parameters:

  • colour colour
  • x int
  • y int
  • w int
  • h int
  • opts
    • blend string

See also:

Img:contrast(amount) line 70

Parameters:

  • amount float -1 to 1
Img:expand(a[, b[, c[, d[, colour=transparent]]]]) line 569
Expands the sides of the image. 1 arg: all sides, 2 args: horizontal, vertical, 4 args: north, west, south, east

Parameters:

  • a int
  • b int (optional)
  • c int (optional)
  • d int (optional)
  • colour colour (default transparent)
Img:fg(colour) line 114
Overlays the colour on top of the image

Parameters:

Img:fill(colour) line 14
Fills the entire image with a single colour

Parameters:

Img:flip(Flag) line 215
Flips the image horizontally and/or vertically, by default just vertically

Parameters:

  • Flag string string like vh

See also:

Img:gamma(amount) line 99

Parameters:

  • amount float 0+
Img:grey() line 47
Img:hue(hue) line 630

Parameters:

  • hue float 0 – 360
Img:invert(stringOrInt) line 12
By default inverts rgb

Parameters:

  • stringOrInt If string inverts channels specified in string like rgba, if int, xors with it directly
Img:kernel(kernel[, opts={}]) line 278
Convolution kernel

Parameters:

  • kernel tab Matrix of any size
  • opts
    • divisor float Value that each kernel entry is divided by, generally to normalise. By default it’s the sum of the kernel (default sum(kernel))
    • bias float Value added to each pixel (default 0)
    • alpha bool Whether to apply the operation to the alpha channel (default false)
Img:line(colour, x1, y1, x2, y2[, opts={}]) line 264

Parameters:

  • colour colour
  • x1 float
  • y1 float
  • x2 float
  • y2 float
  • opts
    • width float (default 1)
    • blend string

See also:

Img:map(strOrFunc) line 153
Runs a function over every pixel in the image. If passed a string and compiled with OpenMP will create separate Lua states in threads and run it in parallel with no access to variables outside the function. More limited but might be faster with very heavy functions and large images. In case of errors in the middle of processing, the image will not be reset. Call img:clone if you plan on recovering errors

Parameters:

  • strOrFunc

Usage:

  • img:map(function(r, g, b, a, x, y) -- Green "nightvision" effect
    	return 0, 1 - g, 0, 1
    end)
  • img:map(function() -- Turns the image into noise
    	local x = math.random(0, img.w - 1)
    	local y = math.random(0, img.h - 1)
    	return img:getPixel(x, y)
    end)
  • img:map([[return function(r, g, b, a)
    	return math.pow(r, 2), math.pow(g, 2), math.pow(b, 2), a
    end]])
Img:mirror() line 100
Flips horizontally

See also:

Img:palette(colours[, opts={}]) line 475

Parameters:

  • colours tab
  • opts
    • dither string none fs (Floyd–Steinberg) fslab (same but in Lab colour space which gives better results but is much slower) (default "none")
Img:poly(colour, points[, opts={}]) line 232
Polygon

Parameters:

  • colour colour
  • points tab {{X,Y}…} Vertex list
  • opts
    • blend string

See also:

Img:rect(colour, x, y, w, h[, opts={}]) line 33

Parameters:

  • colour colour
  • x int
  • y int
  • w int
  • h int
  • opts
    • blend string
    • corners int How many pixels to round the corners

See also:

Img:saturation(saturation) line 645
Changes the saturation. Slower but better than Img:grey

Parameters:

  • saturation float 0 removes colour, 2 doubles colour, 0.5 halves colour, -1 inverts colour
Img:text(font, text[, x=0[, y=0[, opts={}]]]) line 138
Writes text to the image

Parameters:

  • font Font
  • text string
  • x int (default 0)
  • y int (default 0)
  • opts
    • blend string

See also:

Img:trim([threshold=0[, colour=transparent]]) line 513
Trim edges. If the image is blank does nothing, else trims image and returns the image and where the crop starts

Parameters:

  • threshold float A value of 0 matches exactly and a value of 1 makes no sense (default 0)
  • colour colour (default transparent)

Returns:

    img, cropX, cropY

Or

    img

Class Text

Font:colour(colour) line 241
Sets font colour

Parameters:

Font:getColour() line 262
Gets font colour

Returns:

    r, g, b, a
Font:getSize() line 252
Gets font size

Returns:

    w, h
Font:measure(text) line 279
Returns calculated width and height of text

Parameters:

  • text string

Returns:

    w, h
Font:size(w[, y=w]) line 226
Sets font size

Parameters:

  • w int
  • y int (default w)
Font:text(text[, opts={}]) line 203
Creates an image containing just text

Parameters:

  • text string
  • opts tab (default {})
generated by LDoc 1.4.6 Last updated 2023-04-13 13:58:34