py-img-processor 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of py-img-processor might be problematic. Click here for more details.

@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.1
2
+ Name: py-img-processor
3
+ Version: 1.0.0
4
+ Summary: Image editor using Python and Pillow.
5
+ Home-page: https://github.com/SkylerHu/py-img-processor.git
6
+ Author: SkylerHu
7
+ Author-email: skylerhu@qq.com
8
+ License: MIT Licence
9
+ Keywords: image,img-processor,image-processor,imgprocessor,img-editor,image-editor
10
+ Platform: any
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: py-enum >=1.1.1
25
+ Requires-Dist: Pillow >=8
26
+
27
+ # py-img-processor
28
+
29
+ [![PyPI - Version](https://img.shields.io/pypi/v/py-img-processor)](https://github.com/SkylerHu/py-img-processor)
30
+ [![GitHub Actions Workflow Status](https://github.com/SkylerHu/py-img-processor/actions/workflows/pre-commit.yml/badge.svg?branch=master)](https://github.com/SkylerHu/py-img-processor)
31
+ [![GitHub Actions Workflow Status](https://github.com/SkylerHu/py-img-processor/actions/workflows/test-py3.yml/badge.svg?branch=master)](https://github.com/SkylerHu/py-img-processor)
32
+ [![Coveralls](https://img.shields.io/coverallsCoverage/github/SkylerHu/py-img-processor?branch=master)](https://github.com/SkylerHu/py-img-processor)
33
+ [![PyPI - Wheel](https://img.shields.io/pypi/wheel/py-img-processor)](https://github.com/SkylerHu/py-img-processor)
34
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/py-img-processor)](https://github.com/SkylerHu/py-img-processor)
35
+ [![PyPI - Implementation](https://img.shields.io/pypi/implementation/py-img-processor)](https://github.com/SkylerHu/py-img-processor)
36
+ [![GitHub License](https://img.shields.io/github/license/SkylerHu/py-img-processor)](https://github.com/SkylerHu/py-img-processor)
37
+
38
+
39
+ Image editor using Python and Pillow.
40
+
41
+ 依赖Pillow开发的Python库,用于图像编辑处理。
42
+
43
+
44
+ ## 1. 安装
45
+
46
+ pip install py-img-processor
47
+
48
+ 依赖:
49
+
50
+ - `Python >= 3.9`
51
+ - `Pillow >= 8.0.0`
52
+
53
+ 可查看版本变更记录 [ChangeLog](https://github.com/SkylerHu/py-img-processor/blob/master/docs/CHANGELOG-1.x.md)
54
+
55
+ ## 2. 使用(Usage)
56
+
57
+ 具体使用说明查看 [readthedocs](https://py-img-processor.readthedocs.io) 。
58
+
59
+ ## 2.1 运行配置
60
+ 可以通过指定环境变量`PY_SETTINGS_MODULE`加载配置文件:
61
+
62
+ export PY_SETTINGS_MODULE=${your_project.settings_file.py}
63
+
64
+ 支持的配置项有:
65
+
66
+ | 配置项 | 类型 | 说明 | 默认值 |
67
+ | - | - | - | - |
68
+ | DEBUG | bool | 是否debug开发模式 | False |
69
+ | PROCESSOR_MAX_FILE_SIZE | int | 处理原图的大小限制, 单位 MB | 20 |
70
+ | PROCESSOR_MAX_W_H | int | 处理图像,原图宽高像素限制 | 30000 |
71
+ | PROCESSOR_MAX_PIXEL | int | width x height总像素3亿,处理前后的值都被此配置限制 | 300000000 |
72
+ | PROCESSOR_DEFAULT_QUALITY | int | 图像处理后的默认质量 | 75 |
73
+ | PROCESSOR_TEXT_FONT | str | 默认字体文件,默认从系统中寻找;也可以直接传递字体文件路径 | Arial Unicode.ttf |
74
+
75
+ > `注意`:`PROCESSOR_TEXT_FONT` 字体的设置是文字水印必要参数,需保证系统已安装该字体。默认值 `Arial Unicode.ttf` 是MacOS系统存在的字体,建议设置字体文件路径。
76
+
77
+ ## 2.2 图像处理
78
+ ### 处理函数
79
+ `process_image_by_path(input_path, out_path, params)`
80
+
81
+ 参数说明:
82
+
83
+ - `input_path` str,输入图像文件路径
84
+ - `out_path` str, 输出图像保存路径
85
+ - `params` str or json,图像处理参数,参数说明详见 [Reference.md](https://github.com/SkylerHu/py-img-processor/blob/master/docs/Reference.md)
86
+
87
+
88
+ ### 图像处理参数为字符串
89
+
90
+ - 斜线 `/` 隔开,区分不同的操作;
91
+ - 逗号 `,` 隔开,区分操作中不同的参数;
92
+ - 下划线 `_` 隔开,`key_value` 的形式,区分参数的Key和Value;
93
+ - `value`是复杂参数时,需要进行`base64url_encode`,是否需要encode查看文档参数详细说明;
94
+
95
+ ```python
96
+ from imgprocessor.utils import base64url_encode
97
+ from imgprocessor.processor import process_image_by_path
98
+
99
+ process_image_by_path(
100
+ "tests/imgs/lenna-400x225.jpg",
101
+ "/tmp/output.png",
102
+ # 对图片缩放、裁剪、生成圆角、并转成png存储
103
+ "resize,s_1080/crop,w_700,h_700//watermark,text_{base64url_encode('Hello 世界')}/circle,r_10/format,png",
104
+ )
105
+ ```
106
+
107
+ ### 图像处理参数为JSON
108
+ - 只是形式不同,参数和字符串形式无本质区别;
109
+ - `format`、`quality`、`interlace`三个值在JSON第一层,直接按照`key: value`的形式设置;
110
+ - 其他参数都放在 `actions` 数组中;
111
+
112
+ ```python
113
+ process_image_by_path(
114
+ "tests/imgs/lenna-400x225.jpg",
115
+ "/tmp/output.png",
116
+ {
117
+ "actions": [
118
+ {"key": "resize", "s": 1080},
119
+ {"key": "crop", "w": 700, "h": 700},
120
+ # JSON形式参数, text无需encode
121
+ {"key": "watermark", "text": "Hello 世界"},
122
+ {"key": "circle", "r": 10},
123
+ ],
124
+ "format": "png",
125
+ },
126
+ )
127
+ ```
128
+ 该操作与上述字符串示例参数等效。
129
+
130
+ ## 命令行
131
+ 安装库后 有可执行命令 `img-processor` 可以使用,通过 `img-processor -h` 查看参数说明。
132
+
133
+ ```shell
134
+ usage: img-processor [-h] [-V] -P PATH [--action ACTION [ACTION ...]] -O OUTPUT [--overwrite]
135
+
136
+ 图像处理
137
+
138
+ optional arguments:
139
+ -h, --help show this help message and exit
140
+ -V, --version show program's version number and exit
141
+ -P PATH, --path PATH 输入图像的文件路径/目录,若是目录则批量处理目录下所有图像
142
+ --action ACTION [ACTION ...]
143
+ 操作参数,可对同一个文件多组操作
144
+ -O OUTPUT, --output OUTPUT
145
+ 输出图像路径,多个图像或多个操作时请设置已存在的目录
146
+ --overwrite 是否覆盖输出路径中已有文件
147
+ ```
148
+
149
+ 示例:
150
+ ```shell
151
+ # 对单个图像进行多个操作,actions有2个参数,会输出2个图像文件
152
+ img-processor -P tests/imgs/lenna-400x225.jpg -O /tmp/ --action resize,s_300 circle,r_100 --overwrite
153
+ ```
154
+
155
+ > 注意:action参数仅支持字符串表达形式。
156
+
157
+
158
+ ## 提取图像主色调
159
+ ```python
160
+ from imgprocessor.processor import extract_main_color
161
+
162
+ extract_main_color("tests/imgs/lenna-400x225.jpg")
163
+ # 输出: "905C4C"
164
+ ```
@@ -0,0 +1,23 @@
1
+ imgprocessor/__init__.py,sha256=206GfRsPYrYk-XdFXJkzhnAzT02LIJbwQ16L1FHIm3k,2243
2
+ imgprocessor/enums.py,sha256=PgV1KCzdyfOk6VrxmiHZg8mjpYZJ9YG-O-35wtFPah0,3040
3
+ imgprocessor/exceptions.py,sha256=kj9win_XjCbZnXr93sYs4Cfg1hAJX2fn5hgr1YMNoHQ,384
4
+ imgprocessor/main.py,sha256=MtMZPoZkqgnInAzdmediRV6wQUET-R6ELqVAM0X5ql0,3946
5
+ imgprocessor/processor.py,sha256=BADLuZWO7_veLdCi1qcawpVwdz1MOpQTCGorj8K0Fxw,4388
6
+ imgprocessor/utils.py,sha256=KBRQJaN8FuuRD2QQPYuuHQ7S-2ML-ctz4rstQTrEdog,1202
7
+ imgprocessor/parsers/__init__.py,sha256=sFaMrxcGXhF6C53yVwDNcnEL01dACsf2KIZntBbMhm8,2988
8
+ imgprocessor/parsers/alpha.py,sha256=grOnmZSYhO0wI2pJfGz6CfTwOTc8kfcxspmfM0nzAzA,865
9
+ imgprocessor/parsers/base.py,sha256=L66Yn_kEkDGT3bD1AmwxuZQMMMKIw4Qc4NFWX6xOXiY,11938
10
+ imgprocessor/parsers/blur.py,sha256=Y9BeTK7e-y8HPNeLQxgtqiquOVf2cVLXhXn1bv9072g,661
11
+ imgprocessor/parsers/circle.py,sha256=z0IZZSv_zuY2jzB6kN01sB1jGhBure33DPt7JAEeNsk,1653
12
+ imgprocessor/parsers/crop.py,sha256=5Zg_TaAOa-JCZSDEpZqTX0T3sUDoHGJZzXQdOTinbTI,3460
13
+ imgprocessor/parsers/gray.py,sha256=ZDBHZlBfI91TePWWBU0feSHmtD1ekre5-uV2BDLFTKA,396
14
+ imgprocessor/parsers/merge.py,sha256=qKXK9ZUEYvPPBuR-pRvGG-JAuV4Z3aLYbmTjZWkwvNI,4045
15
+ imgprocessor/parsers/resize.py,sha256=Kgayf-VQH9BuLCA77yOoGUTI8NPo9qOK4RitPPXk7I8,4912
16
+ imgprocessor/parsers/rotate.py,sha256=EDKvlxTgZZu7vAkSS9cuZ296dbAhe5Aq6huH9Hjtvy0,722
17
+ imgprocessor/parsers/watermark.py,sha256=HSUnsyyCnG6F6pKSj3NHo8xT2-PC2BpBNve_PQ4cISg,8474
18
+ py_img_processor-1.0.0.dist-info/LICENSE,sha256=Sr4UxtHWGmoO_enyTUeAN276LkBqJpse0guCcb6f9BQ,1066
19
+ py_img_processor-1.0.0.dist-info/METADATA,sha256=pRJTwP-euHavyeQ7hE1Ua7NHJ8BfJxD_AW7bvhfcuwE,6595
20
+ py_img_processor-1.0.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
21
+ py_img_processor-1.0.0.dist-info/entry_points.txt,sha256=MLeLjzpkH7DkDMgICWCQ99D9ElqAvTBVBGA8yjg4dhQ,57
22
+ py_img_processor-1.0.0.dist-info/top_level.txt,sha256=5Pm26oHcqZoihGGxc5N6qQJ2LuVa2i4au_uqHBMqehI,13
23
+ py_img_processor-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ img-processor = imgprocessor.main:main
@@ -0,0 +1 @@
1
+ imgprocessor