https://github.com/smartcrop/smartcrop.py
smartcrop implementation in Python
https://github.com/smartcrop/smartcrop.py
crop-image image-processing python
Last synced: about 1 month ago
JSON representation
smartcrop implementation in Python
- Host: GitHub
- URL: https://github.com/smartcrop/smartcrop.py
- Owner: smartcrop
- License: mit
- Created: 2014-08-13T04:59:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-17T19:15:36.000Z (6 months ago)
- Last Synced: 2025-02-21T14:50:05.254Z (2 months ago)
- Topics: crop-image, image-processing, python
- Language: Python
- Size: 6.29 MB
- Stars: 259
- Watchers: 6
- Forks: 32
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Authors: AUTHORS.md
Awesome Lists containing this project
README
[](https://badge.fury.io/py/smartcrop)
[](https://travis-ci.com/smartcrop/smartcrop.py)# smartcrop.py
smartcrop implementation in Python.
smartcrop finds good crops for arbitrary images and crop sizes, based on
Jonas Wagner\'s [smartcrop.js](https://github.com/jwagner/smartcrop.js).

## Requirements
Python requirements are defined in [pyproject.toml](pyproject.toml).
## Installation
``` sh
pip3 install -U pip setuptools wheel # optional but recommended
pip3 install smartcrop
```or directly from GitHub:
``` sh
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:
``` sh
$ smartcroppy --help
usage: smartcroppy [-h] [--debug-file DEBUG_FILE] [--width WIDTH] [--height HEIGHT] INPUT_FILE OUTPUT_FILEpositional arguments:
INPUT_FILE Input image file
OUTPUT_FILE Output image fileoptions:
-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:
``` sh
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/](examples/) and [smartcrop/cli.py](smartcrop/cli.py) for inspiration):
``` python
import json
import sysimport smartcrop
from PIL import Imageimage = 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`:
``` sh
pip3 install smartcrop[test]
pytest
```## License
MIT