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
| Invocation | Effect |
|---|---|
| lmimg --version | Print the version, for example lmimg 0.1.4 |
| lmimg --notices | Print third-party notices: ImageMagick, zlib, libpng, libjpeg-turbo, libtiff, libwebp, stb_truetype and the embedded Roboto font |
| lmimg --lmcode-schema --json | Print the compiler schema as JSON with keys dsl.schema (2), name (lmimg), types (6), functions (0) and context (1) |
| lmimg --lmcode-schema | Schema output without JSON |
| lmimg --lmcode-signatures | List exact signatures, 279 lines: 1 context line, 72 host methods, 206 standard signatures |
| lmimg --lmcode FILE [FILE ...] | Run compiled bytecode files |
| --dry-run | With --lmcode: verify bytecode without running image operations |
Exit codes and environment
| Code | Meaning |
|---|---|
| 0 | Success |
| 2 | Usage error (failure frame with phase cli, code CLI_USAGE) or invalid LMIMG_MAX_MEMORY_MB |
| 3 | Bytecode-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 |
| Variable | Meaning |
|---|---|
| LMIMG_MAX_MEMORY_MB | Total 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
| Name | Kind | Role |
|---|---|---|
| img | context of type Img | Factory for images and builders, plus utilities |
| Image | type | An RGBA raster, 8 bits per channel; edits mutate and return the receiver |
| Curve | type | Tone curve builder for curves and curves_rgb |
| Layers | type | Layer stack with blend modes, opacity, offsets and masks |
| Montage | type | Grid sheet builder |
| Animation | type | GIF frame sequence builder |
Img methods (context img)
| Signature | Description |
|---|---|
| img.canvas(int, int, float, float, float, float) -> Image | New image of width w and height h filled with colour r, g, b, a |
| img.pattern(int, int, string, string, string, string) -> Image | New 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) -> Image | Load an image file; first frame of an animated input |
| img.hald(int) -> Image | Identity Hald CLUT of side level cubed; level 2..16 |
| img.curve() -> Curve | New curve builder |
| img.layers(int, int) -> Layers | New layer stack of width w and height h |
| img.montage() -> Montage | New montage builder |
| img.animation() -> Animation | New animation builder |
| img.panel(Image, Image, int) -> Image | Two images side by side with a gap in pixels |
| img.text_width(string, float) -> float | Width in pixels of text at the given size in the embedded font |
| img.eval(string) -> float | Evaluate a scalar expression string |
| img.assert_true(bool) -> void | Fail the run when the condition is false |
| img.assert_close(float, float, float) -> void | Fail the run when two values differ by more than the tolerance |
| img.print(string) -> void | Print a value as text |
Image methods
| Signature | Description |
|---|---|
| copy() -> Image | Independent copy |
| save(string) -> void | Write the image to a path; PNG, JPEG, TIFF, WebP, GIF, BMP and PNM are supported |
| width() -> int, height() -> int | Dimensions in pixels |
| pixel(int, int, int) -> float | Channel value at x, y, channel |
| set_pixel(int, int, float, float, float, float) -> Image | Set the pixel at x, y to r, g, b, a |
| resize(int, int) -> Image | Resize to a width and height (bilinear resampling) |
| crop(int, int, int, int) -> Image | Crop to a rectangle |
| rotate(float, float, float, float, float) -> Image | Rotate; non-right angles yield the ImageMagick shear-based extent, slightly larger than the bounding box |
| flip(bool) -> Image | Mirror the image |
| perspective(float, float, float, float, float, float, float, float) -> Image | Perspective transform; bilinear, out-of-frame samples are transparent |
| lens(float) -> Image | Lens distortion with one coefficient; bilinear, out-of-frame samples are transparent |
| levels(float, float, float) -> Image | Levels adjustment |
| curves(Curve) -> Image | Apply one tone curve |
| curves_rgb(Curve, Curve, Curve) -> Image | Apply separate curves to r, g and b |
| hsl(float, float, float) -> Image | Hue, saturation and lightness adjustment |
| channelmix(float x 9) -> Image | Channel mixer with nine float coefficients |
| grayscale() -> Image | Rec.709 luma of the gamma-encoded values |
| sepia(float) -> Image | Sepia treatment |
| invert() -> Image | Invert colours |
| threshold(float) -> Image | Threshold to two levels |
| normalize() -> Image, equalize() -> Image | Contrast normalization and histogram equalization |
| colormap(string) -> Image | False colour: gray, heat, viridis or coolwarm |
| clut(Image) -> Image | Apply a Hald CLUT image with trilinear interpolation |
| blur(float, float) -> Image | Blur; feathers alpha (premultiplied) |
| sharpen(float, float) -> Image | Sharpen; acts on RGB and keeps alpha |
| edges(float) -> Image | Edge detection; acts on RGB and keeps alpha |
| morphology(string, int) -> Image | Morphological operation by name with radius 0..16 |
| unsharp(float, float, float, float) -> Image | Unsharp mask |
| vignette(float, float) -> Image | Vignette |
| tilt_shift(float, float, float) -> Image | Selective-focus band |
| blend(Image, string, float, int, int) -> Image | Composite another image with mode, opacity and offset x, y |
| mask(Image) -> Image | Apply an image mask |
| selection(int, int, int, int) -> Image | Rectangular selection x, y, w, h: clears alpha outside |
| heal(int, int, int, int, int) -> Image | Heal a patch with a planar fit of the surrounding ring |
| rect(float x 8) -> Image | Filled rectangle: four geometry values then r, g, b, a |
| circle(float x 7) -> Image | Filled circle: centre x, centre y, radius, then r, g, b, a |
| line(float x 9) -> Image | Line: x1, y1, x2, y2, then r, g, b, a, then width |
| text(float, float, string, float, float, float, float, float) -> Image | ASCII text at x, y with size, then r, g, b, a |
| mean(int), stddev(int), min(int), max(int) -> float | Statistics; the int argument selects what is measured |
| histogram(string) -> void | Write a 256-bin histogram CSV to a path |
| psnr(Image) -> float | PSNR over normalized RGBA; positive infinity for identical images; equal dimensions required |
| ssim(Image) -> float | One global luma window with sample covariance and constants 0.01 squared and 0.03 squared; equal dimensions required |
| property(string) -> string | Read a property by key |
| metadata(string, string) -> Image | Set a metadata key to a value |
Curve, Layers, Montage and Animation methods
| Signature | Description |
|---|---|
| Curve.point(float, float) -> Curve | Add a control point x, y |
| Layers.add(Image, string, float, int, int) -> Layers | Add a layer with mode, opacity and offset x, y |
| Layers.masked(Image, Image, string, float, int, int) -> Layers | Add a layer with an image mask, mode, opacity and offset x, y |
| Layers.render() -> Image | Flatten the stack |
| Montage.add(Image) -> Montage | Add a tile |
| Montage.render(int, int, float, float, float, float) -> Image | Render with columns, gap and background r, g, b, a |
| Animation.add(Image, int) -> Animation | Add a frame with a delay in centiseconds |
| Animation.size() -> int | Number of frames |
| Animation.save(string) -> void | Write an animated GIF |
Modes and named values
| Set | Values |
|---|---|
| Blend and layer modes | over, multiply, screen, overlay, difference, darken, lighten, addition, subtract, divide (straight-alpha source-over, opacity applied to the source alpha) |
| Colormaps | gray, heat, viridis, coolwarm |
| File formats | PNG, JPEG, TIFF, WebP, GIF, BMP, PNM (PPM, PGM, PBM) |
| Pattern expression functions | hash(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.
| Group | Names |
|---|---|
| Result | lmcode_return_set, lmcode_return_put, lmcode_return_null, lmcode_return_put_null |
| Files | file_read, file_write, file_append, file_exists, file_lines |
| Math | math_abs, math_ceil, math_floor, math_max, math_min, math_pow, math_round, math_sqrt |
| Strings | str_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 templates | json_parse(string) -> Json, template_render(string, Json) -> string |
| Container constructors | int_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 |
| Type | Methods |
|---|---|
| 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 catalog | Names | In lmimg 0.1.4 |
|---|---|---|
| Standard interfaces | RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOption | No |
| Functions | rest_config(string, string) -> void, rest_route(string, string, string) -> void, rest_serve() -> void, rest_stop() -> void, rest_cli(StrList) -> string | No |
| RestExchange | 15 methods on the request and response exchange object | No |