py-img-processor 1.0.0__py3-none-any.whl → 1.0.1__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.
- imgprocessor/__init__.py +1 -1
- imgprocessor/main.py +10 -7
- {py_img_processor-1.0.0.dist-info → py_img_processor-1.0.1.dist-info}/METADATA +29 -9
- {py_img_processor-1.0.0.dist-info → py_img_processor-1.0.1.dist-info}/RECORD +8 -8
- {py_img_processor-1.0.0.dist-info → py_img_processor-1.0.1.dist-info}/LICENSE +0 -0
- {py_img_processor-1.0.0.dist-info → py_img_processor-1.0.1.dist-info}/WHEEL +0 -0
- {py_img_processor-1.0.0.dist-info → py_img_processor-1.0.1.dist-info}/entry_points.txt +0 -0
- {py_img_processor-1.0.0.dist-info → py_img_processor-1.0.1.dist-info}/top_level.txt +0 -0
imgprocessor/__init__.py
CHANGED
imgprocessor/main.py
CHANGED
|
@@ -7,7 +7,7 @@ import argparse
|
|
|
7
7
|
import traceback
|
|
8
8
|
|
|
9
9
|
from imgprocessor import VERSION
|
|
10
|
-
from imgprocessor.processor import process_image_by_path
|
|
10
|
+
from imgprocessor.processor import ProcessParams, process_image_by_path
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def main(argv: typing.Optional[list[str]] = None) -> int:
|
|
@@ -59,21 +59,24 @@ def main(argv: typing.Optional[list[str]] = None) -> int:
|
|
|
59
59
|
print(f_tag, flush=True, end="\r")
|
|
60
60
|
# 相对path的相对路径
|
|
61
61
|
if not base_dir or base_dir in [".", "./"]:
|
|
62
|
-
|
|
62
|
+
input_file_name = file_path
|
|
63
63
|
else:
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
input_file_name = file_path.split(base_dir, 1)[-1]
|
|
65
|
+
input_file_name = input_file_name.strip("/")
|
|
66
66
|
|
|
67
|
-
prefix, ext = os.path.splitext(
|
|
67
|
+
prefix, ext = os.path.splitext(input_file_name)
|
|
68
68
|
for idx, param_str in enumerate(args.action):
|
|
69
|
+
params = ProcessParams.parse_str(param_str)
|
|
69
70
|
# 初始化目标文件路径
|
|
70
71
|
if total == 1 and ac_num == 1 and os.path.splitext(output)[-1]:
|
|
71
72
|
out_path = output
|
|
72
73
|
else:
|
|
74
|
+
if params.save_parser.format:
|
|
75
|
+
ext = f".{params.save_parser.format}"
|
|
73
76
|
if ac_num == 1:
|
|
74
|
-
target_name =
|
|
77
|
+
target_name = f"{prefix}{ext}"
|
|
75
78
|
else:
|
|
76
|
-
target_name = f"{prefix}-{idx}
|
|
79
|
+
target_name = f"{prefix}-{idx}{ext}"
|
|
77
80
|
out_path = os.path.join(output, target_name)
|
|
78
81
|
|
|
79
82
|
tag = f"{f_tag}\t action={idx + 1}\t 保存于 {out_path}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: py-img-processor
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Summary: Image editor using Python and Pillow.
|
|
5
5
|
Home-page: https://github.com/SkylerHu/py-img-processor.git
|
|
6
6
|
Author: SkylerHu
|
|
@@ -75,6 +75,12 @@ Image editor using Python and Pillow.
|
|
|
75
75
|
> `注意`:`PROCESSOR_TEXT_FONT` 字体的设置是文字水印必要参数,需保证系统已安装该字体。默认值 `Arial Unicode.ttf` 是MacOS系统存在的字体,建议设置字体文件路径。
|
|
76
76
|
|
|
77
77
|
## 2.2 图像处理
|
|
78
|
+
|
|
79
|
+
测试图片 `lenna-400x225.jpg` (像素400x225)
|
|
80
|
+
|
|
81
|
+

|
|
82
|
+
|
|
83
|
+
|
|
78
84
|
### 处理函数
|
|
79
85
|
`process_image_by_path(input_path, out_path, params)`
|
|
80
86
|
|
|
@@ -97,13 +103,17 @@ from imgprocessor.utils import base64url_encode
|
|
|
97
103
|
from imgprocessor.processor import process_image_by_path
|
|
98
104
|
|
|
99
105
|
process_image_by_path(
|
|
100
|
-
"
|
|
106
|
+
"docs/imgs/lenna-400x225.jpg",
|
|
101
107
|
"/tmp/output.png",
|
|
102
108
|
# 对图片缩放、裁剪、生成圆角、并转成png存储
|
|
103
|
-
"resize,
|
|
109
|
+
f"resize,s_200/crop,w_200,h_200,g_center/watermark,text_{base64url_encode('Hello 世界')},color_FFF,size_20/circle,r_10/format,png",
|
|
104
110
|
)
|
|
105
111
|
```
|
|
106
112
|
|
|
113
|
+
输出图像 (像素200x200):
|
|
114
|
+
|
|
115
|
+

|
|
116
|
+
|
|
107
117
|
### 图像处理参数为JSON
|
|
108
118
|
- 只是形式不同,参数和字符串形式无本质区别;
|
|
109
119
|
- `format`、`quality`、`interlace`三个值在JSON第一层,直接按照`key: value`的形式设置;
|
|
@@ -111,14 +121,14 @@ process_image_by_path(
|
|
|
111
121
|
|
|
112
122
|
```python
|
|
113
123
|
process_image_by_path(
|
|
114
|
-
"
|
|
124
|
+
"docs/imgs/lenna-400x225.jpg",
|
|
115
125
|
"/tmp/output.png",
|
|
116
126
|
{
|
|
117
127
|
"actions": [
|
|
118
|
-
{"key": "resize", "s":
|
|
119
|
-
{"key": "crop", "w":
|
|
128
|
+
{"key": "resize", "s": 200},
|
|
129
|
+
{"key": "crop", "w": 200, "h": 200, "g": "center"},
|
|
120
130
|
# JSON形式参数, text无需encode
|
|
121
|
-
{"key": "watermark", "text": "Hello 世界"},
|
|
131
|
+
{"key": "watermark", "text": "Hello 世界", "color": "FFF", "size": 20},
|
|
122
132
|
{"key": "circle", "r": 10},
|
|
123
133
|
],
|
|
124
134
|
"format": "png",
|
|
@@ -149,16 +159,26 @@ optional arguments:
|
|
|
149
159
|
示例:
|
|
150
160
|
```shell
|
|
151
161
|
# 对单个图像进行多个操作,actions有2个参数,会输出2个图像文件
|
|
152
|
-
img-processor -P
|
|
162
|
+
img-processor -P docs/imgs/lenna-400x225.jpg -O /tmp/ --action resize,s_200/format,webp resize,s_225/crop,w_225,h_225,g_center/circle/format,png --overwrite
|
|
153
163
|
```
|
|
154
164
|
|
|
155
165
|
> 注意:action参数仅支持字符串表达形式。
|
|
156
166
|
|
|
167
|
+
会输出2个图像文件:
|
|
168
|
+
|
|
169
|
+
`/tmp/lenna-400x225-0.webp` (像素355x200)
|
|
170
|
+
|
|
171
|
+

|
|
172
|
+
|
|
173
|
+
`/tmp/lenna-400x225-1.png` (像素225x225)
|
|
174
|
+
|
|
175
|
+

|
|
176
|
+
|
|
157
177
|
|
|
158
178
|
## 提取图像主色调
|
|
159
179
|
```python
|
|
160
180
|
from imgprocessor.processor import extract_main_color
|
|
161
181
|
|
|
162
|
-
extract_main_color("
|
|
182
|
+
extract_main_color("docs/imgs/lenna-400x225.jpg")
|
|
163
183
|
# 输出: "905C4C"
|
|
164
184
|
```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
imgprocessor/__init__.py,sha256=
|
|
1
|
+
imgprocessor/__init__.py,sha256=KcATKDA1Paed41v9IYB5UxNMvHlpCjASx2wN6CEbFeo,2243
|
|
2
2
|
imgprocessor/enums.py,sha256=PgV1KCzdyfOk6VrxmiHZg8mjpYZJ9YG-O-35wtFPah0,3040
|
|
3
3
|
imgprocessor/exceptions.py,sha256=kj9win_XjCbZnXr93sYs4Cfg1hAJX2fn5hgr1YMNoHQ,384
|
|
4
|
-
imgprocessor/main.py,sha256=
|
|
4
|
+
imgprocessor/main.py,sha256=QDkz__RJ_iIjrb1p56bhPzZ7yLbtzhXvvKpLmvkJEkI,4133
|
|
5
5
|
imgprocessor/processor.py,sha256=BADLuZWO7_veLdCi1qcawpVwdz1MOpQTCGorj8K0Fxw,4388
|
|
6
6
|
imgprocessor/utils.py,sha256=KBRQJaN8FuuRD2QQPYuuHQ7S-2ML-ctz4rstQTrEdog,1202
|
|
7
7
|
imgprocessor/parsers/__init__.py,sha256=sFaMrxcGXhF6C53yVwDNcnEL01dACsf2KIZntBbMhm8,2988
|
|
@@ -15,9 +15,9 @@ imgprocessor/parsers/merge.py,sha256=qKXK9ZUEYvPPBuR-pRvGG-JAuV4Z3aLYbmTjZWkwvNI
|
|
|
15
15
|
imgprocessor/parsers/resize.py,sha256=Kgayf-VQH9BuLCA77yOoGUTI8NPo9qOK4RitPPXk7I8,4912
|
|
16
16
|
imgprocessor/parsers/rotate.py,sha256=EDKvlxTgZZu7vAkSS9cuZ296dbAhe5Aq6huH9Hjtvy0,722
|
|
17
17
|
imgprocessor/parsers/watermark.py,sha256=HSUnsyyCnG6F6pKSj3NHo8xT2-PC2BpBNve_PQ4cISg,8474
|
|
18
|
-
py_img_processor-1.0.
|
|
19
|
-
py_img_processor-1.0.
|
|
20
|
-
py_img_processor-1.0.
|
|
21
|
-
py_img_processor-1.0.
|
|
22
|
-
py_img_processor-1.0.
|
|
23
|
-
py_img_processor-1.0.
|
|
18
|
+
py_img_processor-1.0.1.dist-info/LICENSE,sha256=Sr4UxtHWGmoO_enyTUeAN276LkBqJpse0guCcb6f9BQ,1066
|
|
19
|
+
py_img_processor-1.0.1.dist-info/METADATA,sha256=94yIb7a_Layzuhc-CCa-mmhHB4aPcMv496DvpTTkkR8,7285
|
|
20
|
+
py_img_processor-1.0.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
21
|
+
py_img_processor-1.0.1.dist-info/entry_points.txt,sha256=MLeLjzpkH7DkDMgICWCQ99D9ElqAvTBVBGA8yjg4dhQ,57
|
|
22
|
+
py_img_processor-1.0.1.dist-info/top_level.txt,sha256=5Pm26oHcqZoihGGxc5N6qQJ2LuVa2i4au_uqHBMqehI,13
|
|
23
|
+
py_img_processor-1.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|