lmimg skill: edit, composite and measure images from LMScript

Use this page to write, run and verify an lmimg program on the first try. Every command and output below was produced with lmscript 0.2.482 and the released lmimg 0.1.4 on Linux.

Purpose

lmimg is a native lmcode host for raster image work: procedural canvases and patterns, geometry, tone and colour operations, filters, blend modes, layers with masks, curves, healing, Hald LUTs, drawing and text, montages, GIF animation, and numeric measurements such as PSNR and SSIM. You describe the edit with method calls on the img context inside an _lmcode_ block, run it once, assert the numbers and save image files. A static ImageMagick core does the raster and codec work; no ImageMagick, fonts or codec libraries need to be installed.

When to use it

Install

npm install -g @lmctl-ai/lmctl
lmscript --version

Nothing else is installed by hand. A block that starts with cli="lmimg" install="github:lmctl-ai/lmimg@latest" makes lmscript download the release binary into its tool cache on first use and read the embedded schema from it. The current release contains self-contained Linux x64 and arm64 binaries that need dynamic glibc 2.35 or newer; all third-party libraries, fonts and codecs are linked statically. The repository README asks for lmctl 0.2.401 or newer for autorun.

Commands

CommandUse
lmscript file.lmsCompile the _lmcode_ block, run it in lmimg and continue the outer script with the result map
lmscript --check file.lmsCompile the block against the host schema without running it
lmctl autorun file.lms or lmctl autorun URLRun a local script or a raw example URL, installing hosts as needed
lmimg --versionPrint the host version, for example lmimg 0.1.4
lmimg --noticesPrint the third-party license notices
lmimg --lmcode-signaturesList every signature with exact parameter types (279 lines in 0.1.4)
lmimg --lmcode-schema --jsonPrint the compiler schema as JSON
lmimg --lmcode FILE [FILE ...] [--dry-run]Host protocol used by lmscript: run compiled bytecode; a dry run verifies bytecode without running image operations

Inputs and outputs

Safety rules

Worked examples

Before and after panel with a result map

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");
lmscript quick.lms
{"ok":true,"result":{"width":892,"height":268}}

The run writes images/comparison.png. lmscript --check quick.lms exits 0 for the same file.

Drawing, grading and text (from the repository example before_after_panels.lms)

mkdir("images");
p = _lmcode_ cli="lmimg" install="github:lmctl-ai/lmimg@latest";
let before = img.pattern(420, 480, "0.08 + 0.62*y", "0.12 + 0.38*x", "0.22 + 0.52*(1-y)", "1");
before.circle(210.0, 205.0, 122.0, 0.92, 0.28, 0.18, 1.0);
before.circle(210.0, 205.0, 78.0, 0.96, 0.72, 0.24, 1.0);
before.line(36.0, 352.0, 384.0, 352.0, 0.10, 0.88, 0.78, 1.0, 6.0);
let after = before.copy().levels(0.16, 0.84, 0.82).hsl(198.0, 1.16, 1.02).unsharp(1.4, 0.8, 0.7, 0.0);
before.text(18.0, 38.0, "ORIGINAL", 22.0, 1.0, 1.0, 1.0, 1.0);
after.text(18.0, 38.0, "DELIVERABLE", 22.0, 1.0, 1.0, 1.0, 1.0);
let panel = img.panel(before, after, 20);
panel.resize(900, 520);
panel.save("images/before_after_panels.png");
img.assert_true(panel.width() == 900);
end _lmcode_
r = run_lmcode(p);
assert(r.ok);
print("images/before_after_panels.png");

Run a gallery example from its URL

lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmimg/main/examples/animation_wave.lms

Each repository example compiles and executes itself, asserts its results, writes images/NAME.png in the current directory and prints its output path.

Errors and exit codes

Exit code of lmimgMeaning
0Success
2Usage error or invalid LMIMG_MAX_MEMORY_MB; the failure frame has phase cli and code CLI_USAGE
3Bytecode-load or execution failure, including exceeding the memory budget; JSON error on stdout and a diagnostic line on stderr

A host failure reaches the outer script as a result map. Opening a file that does not exist gives this:

lmscript bad.lms
lmimg: dsl line 2:13: cannot open image file: missing.png
{"ok":false,"phase":"run","code":"RUN_HOST","message":"dsl line 2:13: cannot open image file: missing.png","line":2,"column":13}

In that run the outer script only printed r, so lmscript itself exited 0; add require(r.ok, message) or assert(r.ok) to fail the script.

lmimg --bogus
usage: lmimg --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
Resource limit: LMIMG_MAX_MEMORY_MB (positive whole MiB; default 4096).
LMCODE_RETURN_BEGIN
{"ok":false,"phase":"cli","code":"CLI_USAGE","message":"invalid lmimg arguments"}
LMCODE_RETURN_END

How to verify