cake (**c**ontent-**a**ware **k**ropping [sic] by **e**ntropy) is a
greedy image cropper inspired by Reddit's scraper library. It works
by moving a sliding window over a given image that is continually
reduced to the size of a specified crop width and height. Two copies of
the current window boundary are made, and for each, 16px are cropped on
opposite sides (left-right on the first pass and top-bottom on the
second). The entropies of the cropped windows are compared, and the
smaller of the two will be discarded, moving the window toward the
The current "smart" implementation takes the smaller dimension of the input image as the crop width and height. The optimal crop position is found, and the image is then scaled to 100x100 px.
Make sure that you have
chunky_png installed, and you're good to go.
This has also only been tested on Ruby 1.9.3p0.
Usage: cake.rb [options] <input ...> -o, --output <string> Specify output file -s, --smart Selects the largest, optimal square to crop and rescales. Good for thumbnails. --debug Draws the bounding crop area instead of cropping the image -d <integer>x<integer>, Specify output dimensions (width x height) in pixels --dimensions
$ ruby cake.rb -s cat.png
$ ruby cake.rb --debug -d 240x240 soundlab.png
Because of the large number of colors in an image, it would probably be more ideal to do color quantization before processing.