Skip to main content

smartcrop implementation in Python

Project description

https://travis-ci.com/smartcrop/smartcrop.py.svg?branch=master

smartcrop.py

smartcrop implementation in Python.

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

https://i.gyazo.com/c602d20e025e58f5b15180cd9a262814.jpg https://i.gyazo.com/5fbc9026202f54b13938de621562ed3d.jpg https://i.gyazo.com/88ee22ca9e1dd7e9eba7ea96db084e5e.jpg

Requirements

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 details)

Uploaded Source

Built Distribution

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

smartcrop-0.3.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartcrop-0.3.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.9

File hashes

Hashes for smartcrop-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f9c94d5febb0ac9a68dc623856438a1ca96fa26814974420ac5771b1a599ff8f
MD5 3528faa25a73f64d45159c357f920ba5
BLAKE2b-256 f45e4de74c05ef9de25501f780de1471692224d04c81b0b5db56d5d0945e645d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartcrop-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.9

File hashes

Hashes for smartcrop-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c543f308e85c0d5c42303155f1a2c94d9f88f3e5535ff1dab92f0f306d0de714
MD5 75a8c4e4a75574004452fd74ca6343fd
BLAKE2b-256 3677d24e937e058468724214fbab972a000d670a04d062f9e887caf169461661

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