py-img-processor 1.0.0__py3-none-any.whl → 1.0.2__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 CHANGED
@@ -5,7 +5,7 @@ import importlib
5
5
 
6
6
 
7
7
  __all__ = ["settings", "VERSION"]
8
- __version__ = "1.0.0"
8
+ __version__ = "1.0.2"
9
9
 
10
10
 
11
11
  VERSION = __version__
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
- relative_path = file_path
62
+ input_file_name = file_path
63
63
  else:
64
- relative_path = file_path.split(base_dir, 1)[-1]
65
- relative_path = relative_path.strip("/")
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(relative_path)
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 = relative_path
77
+ target_name = f"{prefix}{ext}"
75
78
  else:
76
- target_name = f"{prefix}-{idx}.{ext}"
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.0
3
+ Version: 1.0.2
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
@@ -23,6 +23,7 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: py-enum >=1.1.1
25
25
  Requires-Dist: Pillow >=8
26
+ Requires-Dist: typing-extensions
26
27
 
27
28
  # py-img-processor
28
29
 
@@ -75,6 +76,12 @@ Image editor using Python and Pillow.
75
76
  > `注意`:`PROCESSOR_TEXT_FONT` 字体的设置是文字水印必要参数,需保证系统已安装该字体。默认值 `Arial Unicode.ttf` 是MacOS系统存在的字体,建议设置字体文件路径。
76
77
 
77
78
  ## 2.2 图像处理
79
+
80
+ 测试图片 `lenna-400x225.jpg` (像素400x225)
81
+
82
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-400x225.jpg)
83
+
84
+
78
85
  ### 处理函数
79
86
  `process_image_by_path(input_path, out_path, params)`
80
87
 
@@ -97,13 +104,17 @@ from imgprocessor.utils import base64url_encode
97
104
  from imgprocessor.processor import process_image_by_path
98
105
 
99
106
  process_image_by_path(
100
- "tests/imgs/lenna-400x225.jpg",
107
+ "docs/imgs/lenna-400x225.jpg",
101
108
  "/tmp/output.png",
102
109
  # 对图片缩放、裁剪、生成圆角、并转成png存储
103
- "resize,s_1080/crop,w_700,h_700//watermark,text_{base64url_encode('Hello 世界')}/circle,r_10/format,png",
110
+ 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
111
  )
105
112
  ```
106
113
 
114
+ 输出图像 (像素200x200):
115
+
116
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-edit.png)
117
+
107
118
  ### 图像处理参数为JSON
108
119
  - 只是形式不同,参数和字符串形式无本质区别;
109
120
  - `format`、`quality`、`interlace`三个值在JSON第一层,直接按照`key: value`的形式设置;
@@ -111,14 +122,14 @@ process_image_by_path(
111
122
 
112
123
  ```python
113
124
  process_image_by_path(
114
- "tests/imgs/lenna-400x225.jpg",
125
+ "docs/imgs/lenna-400x225.jpg",
115
126
  "/tmp/output.png",
116
127
  {
117
128
  "actions": [
118
- {"key": "resize", "s": 1080},
119
- {"key": "crop", "w": 700, "h": 700},
129
+ {"key": "resize", "s": 200},
130
+ {"key": "crop", "w": 200, "h": 200, "g": "center"},
120
131
  # JSON形式参数, text无需encode
121
- {"key": "watermark", "text": "Hello 世界"},
132
+ {"key": "watermark", "text": "Hello 世界", "color": "FFF", "size": 20},
122
133
  {"key": "circle", "r": 10},
123
134
  ],
124
135
  "format": "png",
@@ -149,16 +160,26 @@ optional arguments:
149
160
  示例:
150
161
  ```shell
151
162
  # 对单个图像进行多个操作,actions有2个参数,会输出2个图像文件
152
- img-processor -P tests/imgs/lenna-400x225.jpg -O /tmp/ --action resize,s_300 circle,r_100 --overwrite
163
+ 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
164
  ```
154
165
 
155
166
  > 注意:action参数仅支持字符串表达形式。
156
167
 
168
+ 会输出2个图像文件:
169
+
170
+ `/tmp/lenna-400x225-0.webp` (像素355x200)
171
+
172
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-400x225-0.webp)
173
+
174
+ `/tmp/lenna-400x225-1.png` (像素225x225)
175
+
176
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-400x225-1.png)
177
+
157
178
 
158
179
  ## 提取图像主色调
159
180
  ```python
160
181
  from imgprocessor.processor import extract_main_color
161
182
 
162
- extract_main_color("tests/imgs/lenna-400x225.jpg")
183
+ extract_main_color("docs/imgs/lenna-400x225.jpg")
163
184
  # 输出: "905C4C"
164
185
  ```
@@ -1,7 +1,7 @@
1
- imgprocessor/__init__.py,sha256=206GfRsPYrYk-XdFXJkzhnAzT02LIJbwQ16L1FHIm3k,2243
1
+ imgprocessor/__init__.py,sha256=-x3i8VsW0vQgHc2tjP5nTXdpyHg_VL-QTncjRz2yqoQ,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=MtMZPoZkqgnInAzdmediRV6wQUET-R6ELqVAM0X5ql0,3946
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.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,,
18
+ py_img_processor-1.0.2.dist-info/LICENSE,sha256=Sr4UxtHWGmoO_enyTUeAN276LkBqJpse0guCcb6f9BQ,1066
19
+ py_img_processor-1.0.2.dist-info/METADATA,sha256=I1fjrZJ7XFIjtcp37p2RoQAD2DrG-M0TCMpaTyN5vlk,7318
20
+ py_img_processor-1.0.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
21
+ py_img_processor-1.0.2.dist-info/entry_points.txt,sha256=MLeLjzpkH7DkDMgICWCQ99D9ElqAvTBVBGA8yjg4dhQ,57
22
+ py_img_processor-1.0.2.dist-info/top_level.txt,sha256=5Pm26oHcqZoihGGxc5N6qQJ2LuVa2i4au_uqHBMqehI,13
23
+ py_img_processor-1.0.2.dist-info/RECORD,,