lmimg reference

Complete reference for lmimg 0.1.4. Signatures are copied from lmimg --lmcode-signatures; parameter names come from the repository README and examples. Where the public documentation does not name a parameter, only its type is shown.

CLI flags

InvocationEffect
lmimg --versionPrint the version, for example lmimg 0.1.4
lmimg --noticesPrint third-party notices: ImageMagick, zlib, libpng, libjpeg-turbo, libtiff, libwebp, stb_truetype and the embedded Roboto font
lmimg --lmcode-schema --jsonPrint the compiler schema as JSON with keys dsl.schema (2), name (lmimg), types (6), functions (0) and context (1)
lmimg --lmcode-schemaSchema output without JSON
lmimg --lmcode-signaturesList exact signatures, 279 lines: 1 context line, 72 host methods, 206 standard signatures
lmimg --lmcode FILE [FILE ...]Run compiled bytecode files
--dry-runWith --lmcode: verify bytecode without running image operations

Exit codes and environment

CodeMeaning
0Success
2Usage error (failure frame with phase cli, code CLI_USAGE) or invalid LMIMG_MAX_MEMORY_MB
3Bytecode-load or execution failure with JSON on stdout and a diagnostic on stderr; also exceeding the memory budget, with one stderr line naming LMIMG_MAX_MEMORY_MB
VariableMeaning
LMIMG_MAX_MEMORY_MBTotal memory budget as a positive whole number of MiB; default 4096. The host counts C++ allocations and conservatively charges native image storage.

A host error inside a block reaches the outer script as a map with ok false, phase run, code RUN_HOST, message, line and column.

Context and host types

NameKindRole
imgcontext of type ImgFactory for images and builders, plus utilities
ImagetypeAn RGBA raster, 8 bits per channel; edits mutate and return the receiver
CurvetypeTone curve builder for curves and curves_rgb
LayerstypeLayer stack with blend modes, opacity, offsets and masks
MontagetypeGrid sheet builder
AnimationtypeGIF frame sequence builder

Img methods (context img)

SignatureDescription
img.canvas(int, int, float, float, float, float) -> ImageNew image of width w and height h filled with colour r, g, b, a
img.pattern(int, int, string, string, string, string) -> ImageNew w by h image whose R, G, B and A channels are expression strings over normalized x and y; expressions may use hash(x,y,seed) for white noise and noise(x,y,seed) for smooth value noise
img.open(string) -> ImageLoad an image file; first frame of an animated input
img.hald(int) -> ImageIdentity Hald CLUT of side level cubed; level 2..16
img.curve() -> CurveNew curve builder
img.layers(int, int) -> LayersNew layer stack of width w and height h
img.montage() -> MontageNew montage builder
img.animation() -> AnimationNew animation builder
img.panel(Image, Image, int) -> ImageTwo images side by side with a gap in pixels
img.text_width(string, float) -> floatWidth in pixels of text at the given size in the embedded font
img.eval(string) -> floatEvaluate a scalar expression string
img.assert_true(bool) -> voidFail the run when the condition is false
img.assert_close(float, float, float) -> voidFail the run when two values differ by more than the tolerance
img.print(string) -> voidPrint a value as text

Image methods

SignatureDescription
copy() -> ImageIndependent copy
save(string) -> voidWrite the image to a path; PNG, JPEG, TIFF, WebP, GIF, BMP and PNM are supported
width() -> int, height() -> intDimensions in pixels
pixel(int, int, int) -> floatChannel value at x, y, channel
set_pixel(int, int, float, float, float, float) -> ImageSet the pixel at x, y to r, g, b, a
resize(int, int) -> ImageResize to a width and height (bilinear resampling)
crop(int, int, int, int) -> ImageCrop to a rectangle
rotate(float, float, float, float, float) -> ImageRotate; non-right angles yield the ImageMagick shear-based extent, slightly larger than the bounding box
flip(bool) -> ImageMirror the image
perspective(float, float, float, float, float, float, float, float) -> ImagePerspective transform; bilinear, out-of-frame samples are transparent
lens(float) -> ImageLens distortion with one coefficient; bilinear, out-of-frame samples are transparent
levels(float, float, float) -> ImageLevels adjustment
curves(Curve) -> ImageApply one tone curve
curves_rgb(Curve, Curve, Curve) -> ImageApply separate curves to r, g and b
hsl(float, float, float) -> ImageHue, saturation and lightness adjustment
channelmix(float x 9) -> ImageChannel mixer with nine float coefficients
grayscale() -> ImageRec.709 luma of the gamma-encoded values
sepia(float) -> ImageSepia treatment
invert() -> ImageInvert colours
threshold(float) -> ImageThreshold to two levels
normalize() -> Image, equalize() -> ImageContrast normalization and histogram equalization
colormap(string) -> ImageFalse colour: gray, heat, viridis or coolwarm
clut(Image) -> ImageApply a Hald CLUT image with trilinear interpolation
blur(float, float) -> ImageBlur; feathers alpha (premultiplied)
sharpen(float, float) -> ImageSharpen; acts on RGB and keeps alpha
edges(float) -> ImageEdge detection; acts on RGB and keeps alpha
morphology(string, int) -> ImageMorphological operation by name with radius 0..16
unsharp(float, float, float, float) -> ImageUnsharp mask
vignette(float, float) -> ImageVignette
tilt_shift(float, float, float) -> ImageSelective-focus band
blend(Image, string, float, int, int) -> ImageComposite another image with mode, opacity and offset x, y
mask(Image) -> ImageApply an image mask
selection(int, int, int, int) -> ImageRectangular selection x, y, w, h: clears alpha outside
heal(int, int, int, int, int) -> ImageHeal a patch with a planar fit of the surrounding ring
rect(float x 8) -> ImageFilled rectangle: four geometry values then r, g, b, a
circle(float x 7) -> ImageFilled circle: centre x, centre y, radius, then r, g, b, a
line(float x 9) -> ImageLine: x1, y1, x2, y2, then r, g, b, a, then width
text(float, float, string, float, float, float, float, float) -> ImageASCII text at x, y with size, then r, g, b, a
mean(int), stddev(int), min(int), max(int) -> floatStatistics; the int argument selects what is measured
histogram(string) -> voidWrite a 256-bin histogram CSV to a path
psnr(Image) -> floatPSNR over normalized RGBA; positive infinity for identical images; equal dimensions required
ssim(Image) -> floatOne global luma window with sample covariance and constants 0.01 squared and 0.03 squared; equal dimensions required
property(string) -> stringRead a property by key
metadata(string, string) -> ImageSet a metadata key to a value

Curve, Layers, Montage and Animation methods

SignatureDescription
Curve.point(float, float) -> CurveAdd a control point x, y
Layers.add(Image, string, float, int, int) -> LayersAdd a layer with mode, opacity and offset x, y
Layers.masked(Image, Image, string, float, int, int) -> LayersAdd a layer with an image mask, mode, opacity and offset x, y
Layers.render() -> ImageFlatten the stack
Montage.add(Image) -> MontageAdd a tile
Montage.render(int, int, float, float, float, float) -> ImageRender with columns, gap and background r, g, b, a
Animation.add(Image, int) -> AnimationAdd a frame with a delay in centiseconds
Animation.size() -> intNumber of frames
Animation.save(string) -> voidWrite an animated GIF

Modes and named values

SetValues
Blend and layer modesover, multiply, screen, overlay, difference, darken, lighten, addition, subtract, divide (straight-alpha source-over, opacity applied to the source alpha)
Colormapsgray, heat, viridis, coolwarm
File formatsPNG, JPEG, TIFF, WebP, GIF, BMP, PNM (PPM, PGM, PBM)
Pattern expression functionshash(x,y,seed), noise(x,y,seed), plus arithmetic on normalized x and y

curves_rgb, threshold, invert, normalize, equalize, colormap, clut, hald, text_width, the divide mode and the hash and noise expression functions were added in 0.1.2.

Standard library lmcode_std_v3 in lmimg 0.1.4

lmimg 0.1.4 ships 206 standard signatures: 83 function signatures and 123 container and Json methods. All are callable inside an lmimg block.

GroupNames
Resultlmcode_return_set, lmcode_return_put, lmcode_return_null, lmcode_return_put_null
Filesfile_read, file_write, file_append, file_exists, file_lines
Mathmath_abs, math_ceil, math_floor, math_max, math_min, math_pow, math_round, math_sqrt
Stringsstr_len, str_lower, str_upper, str_trim, str_contains, str_starts_with, str_ends_with, str_find, str_match, str_replace, str_repeat, str_split, str_substr, str_to_int, str_to_float, str_is_int, str_is_float, str_base64_encode, str_base64_decode, str_hex_encode, str_hex_decode
JSON and templatesjson_parse(string) -> Json, template_render(string, Json) -> string
Container constructorsint_list, float_list, str_list, int_map, float_map, str_map, int_queue, float_queue, str_queue, int_stack, float_stack, str_stack, int_pq, float_pq, str_pq
TypeMethods
IntList, FloatList (7 each)add, at, clear, contains, index_of, len, set
StrList (8)add, at, clear, contains, index_of, join, len, set
IntMap, FloatMap, StrMap (10 each)clear, get, get_or, has, key_at, keys, len, remove, set, values
IntQueue, FloatQueue, StrQueue, IntStack, FloatStack, StrStack (7 each)at, clear, empty, len, peek, pop, push
IntPQ, FloatPQ, StrPQ (6 each)clear, empty, len, peek, pop, push
Json (11)as_bool, as_float, as_int, as_string, at, get, has, keys, kind, len, to_json

Standard REST and CLI interfaces

The current lmcode_std_v3 catalog has 226 canonical signatures. The 20 added after the 206 that lmimg 0.1.4 ships are the standard REST and CLI module. lmimg 0.1.4 lists no rest signatures; it picks them up when it syncs to the current catalog and releases.

Part of the current catalogNamesIn lmimg 0.1.4
Standard interfacesRestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOptionNo
Functionsrest_config(string, string) -> void, rest_route(string, string, string) -> void, rest_serve() -> void, rest_stop() -> void, rest_cli(StrList) -> stringNo
RestExchange15 methods on the request and response exchange objectNo