Home

Awesome

croptoelie

Content aware cropping.

Crops images based on entropy: leaving the most interesting part intact.

Don't expect this to be a replacement for human cropping, it is an algorythm and not an extremely smart one at that :).

Best results achieved in combination with scaling: the cropping is then only used to square the image, cutting off the least interesting part. The trimming simply chops off te edge that is least interesting, and continues doing so, untill it reached the requested size.

Usage

Use it in carrierwave, in a custom manipulate! block. For example, carrierwave in a Rails project:

File uploaders/attachement_uploader.rb:

def smart_crop_and_scale(width, height)
  manipulate! do |img|
    img = CropToelie.new(img)
    img = img.smart_crop_and_scale(width, height)
    img = yield(img) if block_given?
    img
  end
end

# Create different versions of your uploaded files:
version :thumb do
  process :smart_crop_and_scale => [80, 80]
end

Contributing to croptoelie

Changelog

2011-04-19: Replace crop with crop! avoids copying large chunks of images around. 2011-04-18: Limit to N steps, instead of step_size. 2011-04-16: Introduce tests and a profiler script, to profile performance.

Todo

Improved algorythm: first @image.scale by F, investigate the entropy on that, most-interesting square by factor F is to-be-cropped area.

Copyright

Copyright (c) 2011 Bèr Kessels. See LICENSE.txt for further details.