ImageMagick image processing via Hot Box containers.
Resize, convert, optimize, and identify images using magick and
magick identify inside isolated containers. Inputs use hot:// storage
URLs; outputs are written back to hot:// storage.
Quick Start
meta ::imagemagick/identify("hot://uploads/photo.jpg")
tap(meta.width)
out ::imagemagick/resize("hot://uploads/photo.jpg", {width: 800, height: 600, fit: "cover"})
tap(out.url)
webp ::imagemagick/convert("hot://uploads/photo.jpg", {format: "webp", quality: 90})
tap(webp.url)
small ::imagemagick/optimize("hot://uploads/photo.jpg")
tap(small.url)
// With explicit output path
out ::imagemagick/resize("hot://uploads/photo.jpg", {
width: 800,
output: "hot://images/photo-800w.jpg",
})
Container Requirements
small
Values
DEFAULT_IMAGE
DEFAULT_IMAGE: Str "alpine:3.21"
INSTALL_CMD
INSTALL_CMD: Str "apk add --no-cache imagemagick libwebp-tools"
Functions
build-convert-args
fn (input-path: Str, output-path: Str, opts: ConvertOpts): Vec<Str>
Build ImageMagick magick arguments for format conversion.
Example
::imagemagick/build-convert-args("/data/in.png", "/data/out.webp", {format: "webp", quality: 85, strip: true})
// ["magick", "/data/in.png", "-quality", "85", "-strip", "/data/out.webp"]
build-identify-args
fn (input-path: Str): Vec<Str>
Build magick identify arguments for verbose-style single-shot metadata
(custom format lines).
Example
first(::imagemagick/build-identify-args("/data/in.jpg")) // "identify"
last(::imagemagick/build-identify-args("/data/in.jpg")) // "/data/in.jpg"
build-optimize-args
fn (input-path: Str, output-path: Str, opts: OptimizeOpts): Vec<Str>
Build ImageMagick magick arguments for optimization (strip, quality).
Example
::imagemagick/build-optimize-args("/data/in.jpg", "/data/out.jpg", {})
// ["magick", "/data/in.jpg", "-strip", "-quality", "85", "/data/out.jpg"]
::imagemagick/build-optimize-args("/data/in.jpg", "/data/out.jpg", {quality: 70, strip: false})
// ["magick", "/data/in.jpg", "-quality", "70", "/data/out.jpg"]
build-resize-args
fn (input-path: Str, output-path: Str, opts: ResizeOpts): Vec<Str>
Build ImageMagick magick arguments for resizing.
Example
::imagemagick/build-resize-args("/data/in.jpg", "/data/out.jpg", {width: 400})
// ["magick", "/data/in.jpg", "-resize", "400x", "/data/out.jpg"]
::imagemagick/build-resize-args("/data/in.jpg", "/data/out.jpg", {width: 400, height: 300, fit: "fill", quality: 80})
// ["magick", "/data/in.jpg", "-resize", "400x300!", "-quality", "80", "/data/out.jpg"]
convert
fn (input: Str, opts: ConvertOpts): Map
Convert an image to another format.
Returns {url: Str, format: Str}.
Example
webp ::imagemagick/convert("hot://uploads/photo.png", {format: "webp", quality: 85, strip: true})
webp.url
small
identify
fn (input: Str): Map
fn (input: Str, image: Str): Map
Read image metadata using identify.
Returns a Map with width, height, format, depth, colorspace, and
filesize (from ImageMagick's %b).
Example
meta ::imagemagick/identify("hot://uploads/photo.jpg")
meta.width
meta.format
nano
optimize
fn (input: Str): Map
fn (input: Str, opts: OptimizeOpts): Map
Optimize file size (strip metadata, adjust quality). Defaults: quality 85, strip true.
Returns {url: Str, format: Str}.
Example
smaller ::imagemagick/optimize("hot://uploads/photo.jpg")
smaller.url
small
parse-identify-output
fn (stdout: Str?): Map
Parse identify -format multi-line output: width, height, format,
depth, colorspace, filesize.
Example
::imagemagick/parse-identify-output("800\n600\nJPEG\n8\nsRGB\n41739B")
// {width: 800, height: 600, format: "JPEG", depth: "8", colorspace: "sRGB", filesize: "41739B"}
resize
fn (input: Str, opts: ResizeOpts): Map
Resize an image with optional fit mode and quality.
Returns {url: Str, format: Str} pointing at Hot storage.
Example
out ::imagemagick/resize("hot://uploads/huge.jpg", {width: 400, height: 300, fit: "cover"})
out.url
small
start-convert
fn (input: Str, opts: ConvertOpts): Map
Start a format-conversion task without awaiting the result.
Returns a TaskInfo map that can be passed to ::task/await later.
Example
task ::imagemagick/start-convert("hot://uploads/photo.png", {format: "webp", quality: 85})
::hot::task/await(task.id)
task.data.output
small
start-identify
fn (input: Str): Map
Start an identify task without awaiting the result.
Returns a TaskInfo map that can be passed to ::task/await later.
Example
task ::imagemagick/start-identify("hot://uploads/photo.jpg")
done ::hot::task/await(task.id)
done.stdout
nano
start-optimize
fn (input: Str): Map
fn (input: Str, opts: OptimizeOpts): Map
Start an optimization task without awaiting the result.
Returns a TaskInfo map that can be passed to ::task/await later.
Example
task ::imagemagick/start-optimize("hot://uploads/photo.jpg")
::hot::task/await(task.id)
task.data.output
// With options
task ::imagemagick/start-optimize("hot://uploads/photo.jpg", {quality: 70, format: "webp"})
small
start-resize
fn (input: Str, opts: ResizeOpts): Map
Start a resize task without awaiting the result.
Returns a TaskInfo map that can be passed to ::task/await later.
Example
task ::imagemagick/start-resize("hot://uploads/photo.jpg", {width: 800})
::hot::task/await(task.id)
task.data.output
small
Types
ConvertOpts
ConvertOpts type {
format: Str,
quality: Int?,
density: Int?,
strip: Bool?,
output: Str?,
image: Str?,
size: Str?
}
Options for format conversion.
Fields
format— Target format, e.g."png","webp","jpg"(required)quality— Quality for lossy formats (1–100)density— DPI for vector or PDF sourcesstrip— Strip metadata whentrueoutput— Outputhot://URL (default: auto-generated)image— Custom Docker image with ImageMagicksize— Box size override (default:"small")
OptimizeOpts
OptimizeOpts type {
quality: Int?,
strip: Bool?,
format: Str?,
output: Str?,
image: Str?,
size: Str?
}
Options for lossy optimization (strip metadata, quality).
Fields
quality— JPEG/WebP quality (default:85)strip— Strip metadata (default:true)format— Output format (default: same as input)output— Outputhot://URL (default: auto-generated)image— Custom Docker image with ImageMagicksize— Box size override (default:"small")
ResizeOpts
ResizeOpts type {
width: Int?,
height: Int?,
fit: Str?,
quality: Int?,
format: Str?,
output: Str?,
image: Str?,
size: Str?
}
Options for resizing an image.
Fields
width— Target width in pixelsheight— Target height in pixelsfit—"contain"(default),"cover", or"fill"quality— Output quality for lossy formats (1–100)format— Output format extension, e.g."png","jpg"(default: input extension)output— Outputhot://URL (default: auto-generated)image— Custom Docker image with ImageMagick pre-installedsize— Box size override (default:"small")