smartcrop implementation in Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples modularization Aug 13, 2014
.gitignore initical commit Aug 13, 2014
README.rst update url Mar 20, 2017 Fixed the logical and operator Dec 10, 2015


smartcrop implementation in Python

smartcrop finds good crops for arbitrary images and crop sizes, based on Jonas Wagner's smartcrop.js


  • PIL or Pillow


pip install --upgrade git+


command-line tool FILE

use module

import sys
import json
from PIL import Image
import smartcrop

sc = smartcrop.SmartCrop()
crop_options = smartcrop.DEFAULTS
crop_options['width'] = 100
crop_options['height'] = 100

img =[1])
ret = sc.crop(img, crop_options)
print(json.dumps(ret, indent=2)) is slower than smartcrop.js

$ identify images/t.jpg
images/t.jpg JPEG 3200x2403 3200x2403+0+0 8-bit DirectClass 2.066MB 0.000u 0:00.000
$ time smartcrop --width 300 --height 300 images/t.jpg
smartcrop --width 300 --height 300 images/t.jpg  0.30s user 0.11s system 100% cpu 0.414 total
$ time smartcroppy --width 300 --height 300 images/t.jpg
smartcroppy --width 300 --height 300 images/t.jpg  3.74s user 0.31s system 99% cpu 4.051 total