lmimg

lmimg is a native lmcode host for image editing, compositing and procedural graphics from scripts: a static ImageMagick core with original GIMP-style layers, masks, curves, healing and LUTs. It is installed automatically by lmscript and reads and writes PNG, JPEG, TIFF, WebP, GIF, BMP and PNM files.

This page is the quick reference. The latest release is lmimg 0.1.4; it ships the 206-signature lmcode_std_v3 standard library next to its 72 host methods.

Install and run

npm install -g @lmctl-ai/lmctl
lmscript quick.lms            # downloads the lmimg release on first use
lmscript --check quick.lms    # compile the _lmcode_ block against the host schema
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmimg/main/examples/animation_wave.lms

The install attribute github:lmctl-ai/lmimg@latest on the block makes lmscript download and cache the release binary. The current release has Linux x64 and arm64 binaries that need dynamic glibc 2.35 or newer; libraries, fonts and codecs are linked statically.

Minimal runnable example

mkdir("images");
prog = _lmcode_ cli="lmimg" install="github:lmctl-ai/lmimg@latest";
let original = img.pattern(440, 260, "x", "y", "0.2", "1");
let edited = original.copy().levels(0.1, 0.8, 0.9);
let panel = img.panel(original, edited, 4);
panel.save("images/comparison.png");
img.assert_close(original.ssim(original), 1.0, 0.000001);
lmcode_return_put("width", panel.width());
lmcode_return_put("height", panel.height());
end _lmcode_
r = run_lmcode(prog);
println(json_stringify(r));
require(r.ok, "comparison failed");

Saved as quick.lms and run with lmscript quick.lms, the program writes images/comparison.png and prints this line:

lmscript quick.lms
{"ok":true,"result":{"width":892,"height":268}}

Host CLI and protocol

InvocationEffectExit
lmimg --versionPrint lmimg and its version, for example lmimg 0.1.40
lmimg --noticesPrint the embedded third-party license notices0
lmimg --lmcode-schema --jsonPrint the compiler schema JSON (schema format 2, name lmimg, 6 host types, one context)0
lmimg --lmcode-signaturesPrint one line per context, function and method signature: 279 lines in 0.1.40
lmimg --lmcode FILE [FILE ...]Run compiled bytecode files; result frame on stdout0 or 3
lmimg --dry-run --lmcode FILE ...Verify bytecode without running image operations0 or 3
Anything elseUsage text on stderr and a failure frame with code CLI_USAGE2
ItemValue
Block headercli="lmimg" install="github:lmctl-ai/lmimg@latest"
Outer callr = run_lmcode(prog) returns a map with ok and result; on failure ok is false and phase, code, message, line and column are set
Result valueSet inside the block with lmcode_return_set(value) or lmcode_return_put(name, value)
Exit codes0 success, 2 usage error or invalid memory setting, 3 bytecode-load or execution failure (including the memory budget)
EnvironmentLMIMG_MAX_MEMORY_MB: total memory budget in whole MiB, default 4096
Standard librarylmcode_std_v3, 206 signatures in release 0.1.4 (the current catalog has 226; see the reference)

Host API quick reference

The single context object is img, of type Img. Image edits mutate their receiver and return it for chaining; use copy() first when the original must survive. Coordinates are pixels and RGBA values are 0..1.

TaskCalls
Create and loadimg.canvas(w, h, r, g, b, a), img.pattern(w, h, R, G, B, A) with expression strings, img.open(path), img.hald(level)
Copy and saveimage.copy(), image.save(path)
Inspect and edit pixelswidth(), height(), pixel(x, y, channel), set_pixel(x, y, r, g, b, a)
Geometryresize, crop, rotate, flip, perspective, lens
Tone and colourlevels, curves, curves_rgb, hsl, channelmix, grayscale, sepia, invert, threshold, normalize, equalize, colormap(name), clut(hald)
Filtersblur, sharpen, edges, morphology, unsharp, vignette, tilt_shift
Compositingblend(image, mode, opacity, x, y), mask(image), selection(x, y, w, h), img.layers(w, h) with add, masked and render
Repair and buildersheal, img.curve().point(x, y), img.montage() with add(image) and render(columns, gap, r, g, b, a)
Drawingrect, circle, line, text, img.text_width(text, size)
Measurementsmean, stddev, min, max, histogram(csv), psnr, ssim, property(key), metadata(key, value)
Sheets and GIFimg.panel(a, b, gap), img.animation() with add(frame, delay), size() and save(path)
Utilitiesimg.eval(expression), img.assert_true(condition), img.assert_close(a, b, tolerance), img.print(text)

Blend and layer modes: over, multiply, screen, overlay, difference, darken, lighten, addition, subtract, divide. Colormaps: gray, heat, viridis, coolwarm.

Detail pages