Skip to content

Guide · Open source

How to use caire: resize images with content-aware seam carving

Updated · written with AI from the project's own documentation and checked against our catalogue data

Caire is an open-source content-aware image resizing tool written in Go. Instead of cropping or stretching a picture, it removes or adds low-energy seams so the main subjects keep their shape. This guide shows how to install it, run it from the command line, use it as a Go library and apply common options such as face detection and batch processing.

Caireesimov/caire · ★ 10.9k · MIT

Quick start

  1. 1Install Go. Install Go, set your GOPATH and add $GOPATH/bin to your PATH.
  2. 2Install caire. Run go install github.com/esimov/caire/cmd/caire@latest, or brew install caire on macOS.
  3. 3Check the flags. Run caire --help to see the supported options.
  4. 4Resize one image. Run caire -in input.jpg -out output.jpg with -width and -height set.
  5. 5Turn on face detection if needed. Add -face=1 to avoid deforming detected faces.
  6. 6Batch process a folder. Pass an input folder and an output folder to process the images concurrently.

What caire does and how seam carving works

Caire is based on the seam carving approach described in the paper Seam Carving for Content-Aware Image Resizing. It first generates an energy map from the image using edge detection.

It then finds connected paths of low-energy pixels, called seams, from top to bottom (or left to right when resizing horizontally). Each seam is removed, and the process repeats until the image reaches the target size.

  • Energy map: edge detection is applied to the input image.
  • Seams: the least important connected pixel paths are found using dynamic programming.
  • Removal: the lowest-cost seam is removed and the process repeats.

Install caire with Go or Homebrew

You need Go installed. Set your GOPATH and make sure $GOPATH/bin is on your PATH, then install the command with Go.

On macOS you can install caire with Homebrew instead.

$ go install github.com/esimov/caire/cmd/caire@latest $ brew install caire

Run caire on a single image

Pass an input file with -in and an output file with -out. The output type is set by the file extension.

Use -help or --help to list the supported flags. The README lists width, height, perc, square, face, mask and rmask among others.

  • -width and -height set the new dimensions in pixels.
  • -preview controls the GUI window and is true by default; set it to false to turn it off.
  • Supported output types are jpg, jpeg, png and bmp.
$ caire -in input.jpg -out output.jpg

Resize by percentage or to a square

Add -perc=1 to treat width and height as percentages instead of pixels. The example below reduces the image by 20% in both directions.

The -square option resizes the image to a square based on the shortest edge.

$ caire -in input/source.jpg -out ./out.jpg -perc=1 -width=20 -height=20 -debug=false

Protect faces with face detection

Use the -face flag to detect human faces before resizing, so the algorithm avoids cutting pixels inside detected faces. No separate classifier file is needed because it is embedded in the binary.

Face detection uses the Pigo library. For its settings, see the Pigo documentation.

$ caire -in input.jpg -out output.jpg -face=1 -perc=1 -width=20

Use stdin, stdout and pipes

Both in and out default to -, so caire can read from a pipe and write to a pipe. You can also pass an image URL to -in, or pipe output from curl or wget.

$ cat input/source.jpg | caire -in - -out - >out.jpg $ cat input/source.jpg | caire >out.jpg $ caire -out out.jpg < input/source.jpg $ curl -s <image_url> | caire > out.jpg

Batch resize a folder

Give caire an input folder and an output folder, along with the new width or height. The README says caire processes the images in the directory concurrently and recursively. The preview window is deactivated in this mode.

$ caire -in <input_folder> -out <output-folder>

What people use it for

  • Resizing a photo for a website while keeping the main subject undistorted
  • Shrinking a folder of images from the command line in one run
  • Keeping faces intact when reducing portrait photos using -face
  • Calling caire from a Go program as a library
  • Piping images through caire in a shell script using stdin and stdout

Frequently asked questions

How do I install caire?

With Go installed, run go install github.com/esimov/caire/cmd/caire@latest. On macOS you can run brew install caire instead. Make sure $GOPATH/bin is on your PATH.

Is caire free to use?

Caire is open source and released under the MIT licence, as shown in its repository. Check the LICENSE file in the project for the full terms.

What do I need to run caire?

The README lists Go as the prerequisite for installing. The GUI preview also needs the dependencies described in the Gio installation notes. Performance figures are not given in the README.

How do I resize an image without distorting faces?

Use the -face flag, which runs face detection before resizing so detected face areas are not cut. The face classifier is built into the binary, so no extra file is needed.

Can caire resize a whole folder?

Yes. Pass an input folder to -in and an output folder to -out. The README says images are processed concurrently and recursively, and the preview window is turned off in this mode.

What are caire's alternatives?

The README lists ImageMagick, libvips and Pigo as comparable projects. For simple resizing that does not need content-aware logic, standard tools are faster and easier, according to the README.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Caire suits Go developers who need content-aware resizing inside a program, and people who want to batch-shrink photos from the command line without distorting subjects. If you only need quick, simple resizing or a full graphical editor, a standard tool or one of the comparable projects such as ImageMagick or libvips is a better fit.

Install options & downloads