Recently I needed to convert a directory of images into thumbnails, with the goal of having each cropped to the same size without losing the focus on the face. While cropping a photo manually isn’t too bad if you just have to do it once, cropping a large set of photos by hand can be extremely time consuming and tedius. Lucikly, Algorithmia offers an algorithm to do just that: Smart Thumbnail.

The Algorithmia way

The Smart Thumbnail algorithm builds on the opencv-based Face Detection algorithm to detect faces and create thumbnails in one fell swoop. I started with this sample set of photos:

Combining the Smart Thumbnail algorithm with the Algorithmia CLI client, it’s simple to create a clean script for thumbnailing an entire directory:

This short and simple code makes it easy to batch process photos, and the results speak for themselves.

As you can see, each image is cropped to the same size, but no one is left with a half a head or their face cut in two. Instead of having to manually crop each photo so that the faces are preserved, I can just run all the photos through the Smart Thumbnail algorithm. Not only is it the intuitive output I was hoping for, but it was also a simple CLI experience with just one clean tool.

One tool, any algorithm

With the Algorithmia CLI I now have a powerful set of algorithms available to me for use across any project or platform. With access to any algorithm in the marketplace, I can now reach for one tool to perform a variety of tasks. Sign up, install the CLI, pick an algorithm, run it with a simple: