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.5.0.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.5.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartcrop-0.5.0.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.5.0.tar.gz
Algorithm Hash digest
SHA256 7df6b004cc1da7f2f47baa3433a9291affc6dab3ca2dd19101e83bef6c5a07aa
MD5 24a9359cc9c7915ff1efddadc619d430
BLAKE2b-256 79020e3fd1b276a19c5be2e938505641756f5be6653f9a00aba88ae62c497dad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartcrop-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9fab10436f3650d995e1e517233a2cf9a52a4c6255e645814dee621d966b0fe
MD5 a09e83440f47b61f1f0c1de63bc67b1c
BLAKE2b-256 a18d4870eedf7f32f6818fd92c0a7f88f471f9b2b777cbb4468c0199c2470def

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