cake
(content-aware kropping [sic] by entropy) 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
larger.
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.
The idea of the contest was that you could do anything (including a bit of resizing) to get a nice crop from the input images. I realize the contest rules were a bit unclear, as the rest of the entries focussed on cropping only. I'm sorry about that.
That said, it was about finding the point of interest in images rather than just cropping and Michael did just that, his implementation just had some extra fancy sauce.
Again, sorry for the confusing contest description, I'll do better next year. ;)