gitmyhub

caire

Go ★ 10k updated 1y ago

Content aware image resize library

Caire is a Go command-line tool that resizes images by intelligently removing the least-important pixels first, so subjects and faces stay intact instead of getting stretched or awkwardly cropped.

Gosetup: easycomplexity 2/5

Caire is a command-line tool and Go library for resizing images in a way that tries to preserve the important parts of the picture. Unlike a standard resize that simply scales everything proportionally, Caire uses a technique called seam carving to figure out which pixels matter least and removes them first.

The way it works is that the tool generates an "energy map" of the image, which is essentially a map that highlights edges and visually important areas. It then finds thin paths through the image, called seams, that pass through the least-important pixels from top to bottom or left to right. Removing those seams shrinks the image in one direction without distorting the main subjects. The process can also be run in reverse to expand an image by inserting new seams.

A notable feature is built-in face detection. When enabled, the tool identifies human faces in the image before resizing and marks those regions as high-importance zones, so the algorithm avoids cutting through them. This prevents the common problem where resizing a photo crops someone's face awkwardly.

The tool includes a live preview window that shows the seam removal happening in real time. You can watch the image shrink step by step. This preview can be disabled when processing many files at once.

Caire supports batch processing of entire folders, accepting all images in a directory and resizing them concurrently. It also supports reading from and writing to standard input and output, which allows it to be combined with other command-line tools. Accepted input formats include JPEG, PNG, and BMP. Mask files can also be provided to explicitly protect certain areas from being changed or to force certain areas to be removed.

Installation is available through the Go toolchain, Homebrew on macOS, and as a Snap package on Linux. The tool is used as a standalone command-line program or imported as a library into Go projects.

Where it fits