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 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.1"
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.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
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-400x225.jpg)
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
- "tests/imgs/lenna-400x225.jpg",
106
+ "docs/imgs/lenna-400x225.jpg",
101
107
  "/tmp/output.png",
102
108
  # 对图片缩放、裁剪、生成圆角、并转成png存储
103
- "resize,s_1080/crop,w_700,h_700//watermark,text_{base64url_encode('Hello 世界')}/circle,r_10/format,png",
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
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-edit.png)
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
- "tests/imgs/lenna-400x225.jpg",
124
+ "docs/imgs/lenna-400x225.jpg",
115
125
  "/tmp/output.png",
116
126
  {
117
127
  "actions": [
118
- {"key": "resize", "s": 1080},
119
- {"key": "crop", "w": 700, "h": 700},
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 tests/imgs/lenna-400x225.jpg -O /tmp/ --action resize,s_300 circle,r_100 --overwrite
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
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-400x225-0.webp)
172
+
173
+ `/tmp/lenna-400x225-1.png` (像素225x225)
174
+
175
+ ![](https://github.com/SkylerHu/py-img-processor/blob/master/docs/imgs/lenna-400x225-1.png)
176
+
157
177
 
158
178
  ## 提取图像主色调
159
179
  ```python
160
180
  from imgprocessor.processor import extract_main_color
161
181
 
162
- extract_main_color("tests/imgs/lenna-400x225.jpg")
182
+ extract_main_color("docs/imgs/lenna-400x225.jpg")
163
183
  # 输出: "905C4C"
164
184
  ```
@@ -1,7 +1,7 @@
1
- imgprocessor/__init__.py,sha256=206GfRsPYrYk-XdFXJkzhnAzT02LIJbwQ16L1FHIm3k,2243
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=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.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,,