Home

Awesome

smartcropper

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 = SmartCropper.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.

Roadmap

  1. Refactoring: It must be cleaned up. There is a lot of smelly code, fat methods and DRY.
  2. Performance: I want to make it smarter when cropping (really) large images.
  3. Improve slicing. The results are okay-ish when merely squaring images, but lack when you cut tiny areas from a large image.
  4. Release 1.0.0

Copyright

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