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
| Invocation | Effect | Exit |
|---|---|---|
| lmimg --version | Print lmimg and its version, for example lmimg 0.1.4 | 0 |
| lmimg --notices | Print the embedded third-party license notices | 0 |
| lmimg --lmcode-schema --json | Print the compiler schema JSON (schema format 2, name lmimg, 6 host types, one context) | 0 |
| lmimg --lmcode-signatures | Print one line per context, function and method signature: 279 lines in 0.1.4 | 0 |
| lmimg --lmcode FILE [FILE ...] | Run compiled bytecode files; result frame on stdout | 0 or 3 |
| lmimg --dry-run --lmcode FILE ... | Verify bytecode without running image operations | 0 or 3 |
| Anything else | Usage text on stderr and a failure frame with code CLI_USAGE | 2 |
| Item | Value |
|---|---|
| Block header | cli="lmimg" install="github:lmctl-ai/lmimg@latest" |
| Outer call | r = 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 value | Set inside the block with lmcode_return_set(value) or lmcode_return_put(name, value) |
| Exit codes | 0 success, 2 usage error or invalid memory setting, 3 bytecode-load or execution failure (including the memory budget) |
| Environment | LMIMG_MAX_MEMORY_MB: total memory budget in whole MiB, default 4096 |
| Standard library | lmcode_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.
| Task | Calls |
|---|---|
| Create and load | img.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 save | image.copy(), image.save(path) |
| Inspect and edit pixels | width(), height(), pixel(x, y, channel), set_pixel(x, y, r, g, b, a) |
| Geometry | resize, crop, rotate, flip, perspective, lens |
| Tone and colour | levels, curves, curves_rgb, hsl, channelmix, grayscale, sepia, invert, threshold, normalize, equalize, colormap(name), clut(hald) |
| Filters | blur, sharpen, edges, morphology, unsharp, vignette, tilt_shift |
| Compositing | blend(image, mode, opacity, x, y), mask(image), selection(x, y, w, h), img.layers(w, h) with add, masked and render |
| Repair and builders | heal, img.curve().point(x, y), img.montage() with add(image) and render(columns, gap, r, g, b, a) |
| Drawing | rect, circle, line, text, img.text_width(text, size) |
| Measurements | mean, stddev, min, max, histogram(csv), psnr, ssim, property(key), metadata(key, value) |
| Sheets and GIF | img.panel(a, b, gap), img.animation() with add(frame, delay), size() and save(path) |
| Utilities | img.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
- Skill: install, commands, safety rules, worked examples, errors and verification for agents.
- Guide: the image model, architecture, workflow and limits.
- Reference: every type, method signature, mode, flag, exit code and the standard library tables.
- GitHub repository lmctl-ai/lmimg: README, 30 gallery examples and releases.