Cropping an image with a script is not a big deal as there are many libraries available in every language, but some could lead to the following case :

duck_bad_crop

A few web searches about “failsafe crop” led us to a very interesting paper : A Unified Approach to Salient Object Detection via Low Rank Matrix Recovery

Unfortunately, it involves multiple steps  and a lot of computing (~ 3 to 6 seconds per image).

We developed a python module to optimize crop quality, based on the concept of maximum entropy (ie : maximum quantity of information).

cropy is in early stage and has some issue but gives some good results if the crop width or height is not far from the original image.

Here are some sample crops with different ratio, based on the previous image.

Original image (800×600)

duck

Crop 800×600

duck.800.400

Crop 600×400

duck.600.400

Crop 600×300

duck.600.300

Crop 400×500

duck.400.500

Crop 300×500

duck.300.500

Crop 200×572

duck.200.572

Install Cropy

The whole project is open source and hosted on Github. We’d love to hear from you if you’d like to contribute!

Some other useful links :

  • Slycrop : A similar project in PHP
  • cake : A similar project in Ruby
  • Croppola offers an online service for automatic cropping (no API)