Skip to main content

smartcrop implementation in Python

Project description

image

Python package

smartcrop.py

smartcrop implementation in Python.

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

image image image

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.2.tar.gz (6.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartcrop-0.4.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file smartcrop-0.4.2.tar.gz.

File metadata

  • Download URL: smartcrop-0.4.2.tar.gz
  • Upload date:
  • Size: 6.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for smartcrop-0.4.2.tar.gz
Algorithm Hash digest
SHA256 ed8e6307d5e4038aa40200f6e7e2274fa68ac68363554269cf269076e128852f
MD5 f639353ea4bb643b4b7f6e6a762d0967
BLAKE2b-256 3013e9e4ecdcc7801958fef1726811dd13d0182e78fc3816dec840020c924f6a

See more details on using hashes here.

File details

Details for the file smartcrop-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: smartcrop-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for smartcrop-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dda76caff146b1f3908c76e8de9f1b5a05a911d4a36422856b237605f14d1c3e
MD5 563a7125a4ea65eac84c17b2d7fa02a9
BLAKE2b-256 74c6b9eecdae551aba68ffeea30c6fc6656f7b8a775aa57febaeecb0c91ff2f6

See more details on using hashes here.

Supported by

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