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
Python requirements are defined in pyproject.toml.
Installation
pip3 install -U pip setuptools wheel # optional but recommended
pip3 install smartcrop
or directly from GitHub:
pip3 install -U pip setuptools wheel # optional but recommended
pip install -e git+git://github.com/smartcrop/smartcrop.py.git@master#egg=smartcrop
Usage
Use the basic command-line tool:
$ smartcroppy --help
usage: smartcroppy [-h] [--debug-file DEBUG_FILE] [--width WIDTH] [--height HEIGHT] INPUT_FILE OUTPUT_FILE
positional arguments:
INPUT_FILE Input image file
OUTPUT_FILE Output image file
options:
-h, --help show this help message and exit
--debug-file DEBUG_FILE
Debugging image file
--width WIDTH Crop width
--height HEIGHT Crop height
Processing an image:
smartcroppy --width 300 --height 300 tests/images/business-work-1.jpg output.jpg --debug-file debug.jpg
Or use the module it in your code (this is a really basic example, see examples/ and smartcrop/cli.py for inspiration):
import json
import sys
import smartcrop
from PIL import Image
image = Image.open(sys.argv[1])
cropper = smartcrop.SmartCrop()
result = cropper.crop(image, 100, 100)
print(json.dumps(result, indent=2))
Testing
Install dependencies for testing, then call pytest
:
pip3 install smartcrop[test]
pytest
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.4.1.tar.gz
(6.6 MB
view details)
Built Distribution
File details
Details for the file smartcrop-0.4.1.tar.gz
.
File metadata
- Download URL: smartcrop-0.4.1.tar.gz
- Upload date:
- Size: 6.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3acc29f4e5ab9de29a870e05078faab8e7d2d72fbf4ec7b7cdc1ae391cd10e4e |
|
MD5 | 1dc32bad7ca6550e06a21f686484a68d |
|
BLAKE2b-256 | fd84ce7f973934ce80edd69cfc80c1fbff17c2736e9caa2ea426b63338b86aaf |
File details
Details for the file smartcrop-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: smartcrop-0.4.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2367d8712468dd33909d55f15db2720f31c1863e9b59bd55231d83c06ca4d78 |
|
MD5 | 0d40430bc09a347ed725022a089acb27 |
|
BLAKE2b-256 | 5d4d67704e29d1897a2c6c615adb6362431b94632827cd379ff6ced51c7a8b96 |