Skip to main content

smartcrop implementation in Python

Project description

https://travis-ci.com/smartcrop/smartcrop.py.svg?branch=master

smartcrop.py

smartcrop implementation in Python

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

https://i.gyazo.com/c602d20e025e58f5b15180cd9a262814.jpg https://i.gyazo.com/5fbc9026202f54b13938de621562ed3d.jpg https://i.gyazo.com/88ee22ca9e1dd7e9eba7ea96db084e5e.jpg

Requirements

  • PIL or Pillow

Installation

pip2 install smartcrop
pip3 install smartcrop

or directly from GitHub:

pip install -e git+git://github.com/hhatto/smartcrop.py.git@master#egg=smartcrop

Usage

command-line tool

smartcrop.py FILE

use module

import json
import sys

import smartcrop
from PIL import Image

image = Image.open(sys.argv[1])

sc = smartcrop.SmartCrop()
result = sc.crop(image, 100, 100)
print(json.dumps(result, indent=2))

smartcrop.py 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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartcrop-0.3.0.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distributions

smartcrop-0.3.0-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

smartcrop-0.3.0-py2-none-any.whl (7.2 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page