smartcrop.py

在 Python 中实现 smartcrop。smartcrop 基于 Jonas Wagner 的 smartcrop.js,为任意的图片和裁剪尺寸找到好的裁剪。「smartcrop implementation in Python. smartcrop finds good crops for arbitrary images and crop sizes, based on Jonas Wagner's smartcrop.js.」

Github星跟蹤圖

.. image:: https://travis-ci.com/smartcrop/smartcrop.py.svg?branch=master
:target: 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_

.. _smartcrop.js: https://github.com/jwagner/smartcrop.js

.. image:: https://i.gyazo.com/c602d20e025e58f5b15180cd9a262814.jpg
:width: 50%

.. image:: https://i.gyazo.com/5fbc9026202f54b13938de621562ed3d.jpg
:width: 25%

.. image:: https://i.gyazo.com/88ee22ca9e1dd7e9eba7ea96db084e5e.jpg
:width: 50%

Requirements

  • PIL or Pillow

Installation

.. code-block:: sh

pip2 install smartcrop
pip3 install smartcrop

or directly from GitHub:

.. code-block:: sh

pip install -e git+git://github.com/hhatto/smartcrop.py.git@master#egg=smartcrop

Usage

command-line tool

.. code-block:: sh

smartcrop.py FILE

use module

.. code-block:: python

import json
import sys

import smartcrop
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))

smartcrop.py is slower than smartcrop.js_

.. code-block:: sh

$ identify images/t.jpg
images/t.jpg JPEG 3200x2403 3200x2403+0+0 8-bit DirectClass 2.066MB 0.000u 0:00.000
$ time smartcrop --width 300 --height 300 images/t.jpg
smartcrop --width 300 --height 300 images/t.jpg  0.30s user 0.11s system 100% cpu 0.414 total
$ time smartcroppy --width 300 --height 300 images/t.jpg
smartcroppy --width 300 --height 300 images/t.jpg  3.74s user 0.31s system 99% cpu 4.051 total

License

MIT

主要指標

概覽
名稱與所有者smartcrop/smartcrop.py
主編程語言Python
編程語言Python (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2014-08-13 04:59:45
推送於2024-10-17 19:15:36
最后一次提交2024-10-17 21:14:53
發布數10
最新版本名稱v0.4.1 (發布於 )
第一版名稱v0.1 (發布於 )
用户参与
星數262
關注者數5
派生數32
提交數142
已啟用問題?
問題數25
打開的問題數7
拉請求數16
打開的拉請求數0
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?