← Back to solutions
AppGoFree

ImageMagick MCP — Image Resize & Crop for AI Agents

Before: resizing images to exact dimensions inside an agent workflow meant shelling out to a command, managing aspect ratio math manually, and handling padding edge cases by hand. After: one tool call — the agent specifies dimensions and mode, gets a finished file.

Challenge

AI agents working with images frequently need to resize them to exact pixel dimensions — thumbnails, social media crops, platform-specific aspect ratios. The naive approach is to construct a shell command, but that requires the agent to know ImageMagick's CLI flags, handle aspect ratio mismatches correctly, and produce clean results across blur, crop, and letterbox scenarios. One wrong flag and the output is distorted or empty.

Options Considered

  1. Ask the agent to run ImageMagick shell commands directly — works in theory, but constructing correct convert pipelines for all three aspect ratio modes is error-prone and produces inconsistent results across agent sessions.
  2. Python script with Pillow — reliable, but requires a Python environment, adds a dependency, and still needs to be wired up as a tool for the agent to call.
  3. Go MCP server wrapping ImageMagick — chosen. Single self-contained binary; the agent passes input path, output path, and dimensions; the server handles all ImageMagick logic internally.

Decision

A minimal Go MCP server that exposes one focused tool: crop_resize_blur_bg. The agent provides an input path, output path, target width and height, and optionally a mode. The server handles the resize — with correct aspect ratio treatment in all cases — and returns the output path when done.

Implementation

The server wraps ImageMagick via shell execution with a fixed, validated command template — no user-constructed CLI strings. Three modes cover every common layout need: blur fills the background with a blurred version of the source image (default, looks natural for any content), cover crops to fill the frame with no padding, and contain fits the image inside the target with solid padding. Blur radius is configurable.

The binary is statically compiled and cross-built for macOS, Linux, and Windows (amd64 + arm64). No runtime dependencies beyond ImageMagick itself. Integrates with any MCP-compatible host via a single entry in the host's server config.

Outcome

Resizing images inside an agent workflow is now a single deterministic tool call. The agent no longer needs to know ImageMagick's API — it specifies intent (dimensions, mode), and the server produces a correct result every time. Batch resize pipelines chain multiple calls without any manual intervention.

Open for contract collaboration

I am available for contract-based collaboration. If you have an interesting project idea, schedule a call via Calendly.

Schedule a 30-min call