smartcrop implementation in Python
Project description
smartcrop.py
smartcrop implementation in Python.
smartcrop finds good crops for arbitrary images and crop sizes, based on Jonas Wagner’s smartcrop.js.
Requirements
PIL or Pillow
numpy for smartcrop_numpy.py (see https://github.com/smartcrop/smartcrop.py/issues/12)
Installation
pip3 install smartcrop
pip3 install numpy # if you want to use smartcrop_numpy.py
or directly from GitHub:
pip install -e git+git://github.com/hhatto/smartcrop.py.git@master#egg=smartcrop
Usage
Use the basic command-line tool:
$ smartcroppy --help
usage: smartcroppy [-h] [--debug] [--width WIDTH] [--height HEIGHT]
INPUT_FILE OUTPUT_FILE
positional arguments:
INPUT_FILE input image file
OUTPUT_FILE output image file
optional arguments:
-h, --help show this help message and exit
--debug debug mode
--width WIDTH crop width
--height HEIGHT crop height
Processing an image:
smartcroppy --width 300 --height 300 tests/images/business-work-1.jpg output.jpg
Or use the module it in your code (this is a really basic example):
import json
import sys
import smartcrop # or smartcrop_numpy
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))
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.1.tar.gz
(5.9 kB
view hashes)
Built Distribution
Close
Hashes for smartcrop-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c543f308e85c0d5c42303155f1a2c94d9f88f3e5535ff1dab92f0f306d0de714 |
|
MD5 | 75a8c4e4a75574004452fd74ca6343fd |
|
BLAKE2b-256 | 3677d24e937e058468724214fbab972a000d670a04d062f9e887caf169461661 |