Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

smartcrop implementation in Python

Project description

.. image::
smartcrop implementation in Python

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

.. _`smartcrop.js`:

.. image::
:width: 50%

.. image::
:width: 25%

.. image::
:width: 50%

* PIL or Pillow

.. code-block:: sh

pip install --upgrade git+

command-line tool

.. code-block:: sh FILE

use module

.. code-block:: python

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`_

.. code-block:: sh

$ 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


Project details

Release history Release notifications

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
smartcrop-0.2.1-py3-none-any.whl (7.1 kB) Copy SHA256 hash SHA256 Wheel py3
smartcrop-0.2.1.tar.gz (5.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page