img-resize-kit 1.0.0__tar.gz

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.
@@ -0,0 +1,16 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BoiledSaltedDuck
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: img-resize-kit
3
+ Version: 1.0.0
4
+ Summary: 图片批量缩放与压缩工具 - 批量调整图片尺寸、压缩图片大小、查看图片信息
5
+ Author-email: BoiledSaltedDuck <tools@office-tools.pro>
6
+ License: MIT
7
+ Keywords: image,resize,compress,图片缩放,图片压缩,batch
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Multimedia :: Graphics
12
+ Classifier: Topic :: Utilities
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: Pillow>=9.0
17
+ Dynamic: license-file
18
+
19
+ # img-resize-kit 图片批量缩放与压缩工具
20
+
21
+ [![PyPI version](https://img.shields.io/pypi/v/img-resize-kit)](https://pypi.org/project/img-resize-kit/)
22
+ [![Downloads](https://img.shields.io/pypi/dm/img-resize-kit)](https://pypi.org/project/img-resize-kit/)
23
+ [![License](https://img.shields.io/pypi/l/img-resize-kit)](https://github.com/BoiledSaltedDuck/img-resize-kit/blob/main/LICENSE)
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install img-resize-kit
29
+ ```
30
+
31
+ ## 用法
32
+
33
+ ```bash
34
+ # 批量缩放图片(保持宽高比)
35
+ img-resize resize ./图片/ 800 600 ./输出/
36
+
37
+ # 批量压缩图片
38
+ img-resize compress ./图片/ 80
39
+
40
+ # 查看图片信息
41
+ img-resize info ./图片/
42
+ ```
43
+
44
+ ## 功能
45
+
46
+ ### 缩放 (resize)
47
+ - 批量调整图片到指定尺寸
48
+ - 默认保持宽高比
49
+ - 使用 LANCZOS 高质量重采样算法
50
+
51
+ ### 压缩 (compress)
52
+ - 批量压缩 JPEG 图片(调整质量参数)
53
+ - PNG 图片自动优化
54
+ - 显示压缩前后的文件大小对比
55
+
56
+ ### 信息 (info)
57
+ - 扫描目录中所有图片
58
+ - 显示格式、尺寸、文件大小
59
+
60
+ ## 支持
61
+
62
+ 如果 img-resize-kit 帮到了您,欢迎打赏支持:
63
+
64
+ ```
65
+ USDT (TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa
66
+ ```
67
+
68
+ 您的支持是开源项目持续发展的动力 ❤️
@@ -0,0 +1,50 @@
1
+ # img-resize-kit 图片批量缩放与压缩工具
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/img-resize-kit)](https://pypi.org/project/img-resize-kit/)
4
+ [![Downloads](https://img.shields.io/pypi/dm/img-resize-kit)](https://pypi.org/project/img-resize-kit/)
5
+ [![License](https://img.shields.io/pypi/l/img-resize-kit)](https://github.com/BoiledSaltedDuck/img-resize-kit/blob/main/LICENSE)
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pip install img-resize-kit
11
+ ```
12
+
13
+ ## 用法
14
+
15
+ ```bash
16
+ # 批量缩放图片(保持宽高比)
17
+ img-resize resize ./图片/ 800 600 ./输出/
18
+
19
+ # 批量压缩图片
20
+ img-resize compress ./图片/ 80
21
+
22
+ # 查看图片信息
23
+ img-resize info ./图片/
24
+ ```
25
+
26
+ ## 功能
27
+
28
+ ### 缩放 (resize)
29
+ - 批量调整图片到指定尺寸
30
+ - 默认保持宽高比
31
+ - 使用 LANCZOS 高质量重采样算法
32
+
33
+ ### 压缩 (compress)
34
+ - 批量压缩 JPEG 图片(调整质量参数)
35
+ - PNG 图片自动优化
36
+ - 显示压缩前后的文件大小对比
37
+
38
+ ### 信息 (info)
39
+ - 扫描目录中所有图片
40
+ - 显示格式、尺寸、文件大小
41
+
42
+ ## 支持
43
+
44
+ 如果 img-resize-kit 帮到了您,欢迎打赏支持:
45
+
46
+ ```
47
+ USDT (TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa
48
+ ```
49
+
50
+ 您的支持是开源项目持续发展的动力 ❤️
@@ -0,0 +1,4 @@
1
+ """img-resize-kit - 图片批量缩放与裁剪工具"""
2
+
3
+ __version__ = "1.0.0"
4
+ from . import resizer
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ img-resize-kit - 图片批量缩放与裁剪工具
4
+ 功能:批量缩放、裁剪、压缩图片
5
+ 用法:img-resize [输入目录] [宽度] [高度] [输出目录]
6
+ img-resize resize ./图片/ 800 600 ./输出/
7
+ img-resize compress ./图片/ 80
8
+ img-resize info ./图片/
9
+ """
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ try:
14
+ from PIL import Image
15
+ except ImportError:
16
+ print("正在安装 Pillow...")
17
+ import subprocess
18
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "Pillow", "-q"])
19
+ from PIL import Image
20
+
21
+
22
+ SUPPORTED_EXTS = {'.jpg', '.jpeg', '.png', '.webp', '.bmp', '.tiff'}
23
+
24
+
25
+ def _get_images(input_dir):
26
+ """获取目录下所有支持的图片文件"""
27
+ p = Path(input_dir)
28
+ if not p.exists():
29
+ return None, f"目录 {input_dir} 不存在"
30
+
31
+ files = []
32
+ for ext in SUPPORTED_EXTS:
33
+ files.extend(list(p.glob(f"*{ext}")) + list(p.glob(f"*{ext.upper()}")))
34
+ files.sort()
35
+
36
+ if not files:
37
+ return None, f"目录 {input_dir} 中没有找到支持的图片文件"
38
+
39
+ return files, None
40
+
41
+
42
+ def resize_images(input_dir, width, height, output_dir=None, keep_aspect=True):
43
+ """批量缩放图片"""
44
+ files, error = _get_images(input_dir)
45
+ if error:
46
+ print(f"错误: {error}")
47
+ return False
48
+
49
+ if output_dir:
50
+ out_path = Path(output_dir)
51
+ else:
52
+ out_path = Path(input_dir) / f"resized_{width}x{height}"
53
+ out_path.mkdir(parents=True, exist_ok=True)
54
+
55
+ print(f"找到 {len(files)} 个图片文件,目标尺寸: {width}x{height}")
56
+ success = 0
57
+
58
+ for f in files:
59
+ try:
60
+ img = Image.open(f)
61
+
62
+ # 计算新尺寸
63
+ if keep_aspect:
64
+ img.thumbnail((width, height), Image.LANCZOS)
65
+ else:
66
+ img = img.resize((width, height), Image.LANCZOS)
67
+
68
+ out_file = out_path / f.name
69
+ # 保持原始格式
70
+ format_map = {'.jpg': 'JPEG', '.jpeg': 'JPEG', '.png': 'PNG', '.webp': 'WEBP', '.bmp': 'BMP', '.tiff': 'TIFF'}
71
+ fmt = format_map.get(f.suffix.lower(), 'JPEG')
72
+ if fmt == 'JPEG' and img.mode in ('RGBA', 'P'):
73
+ img = img.convert('RGB')
74
+ img.save(out_file, format=fmt, quality=95)
75
+
76
+ success += 1
77
+ print(f" ✓ {f.name} ({img.size[0]}x{img.size[1]})")
78
+ except Exception as e:
79
+ print(f" ✗ {f.name} 处理失败: {e}")
80
+
81
+ print(f"\n完成!成功处理 {success}/{len(files)} 个文件")
82
+ print(f"输出目录: {out_path}")
83
+ return success > 0
84
+
85
+
86
+ def compress_images(input_dir, quality=80, output_dir=None):
87
+ """批量压缩图片(降低质量以减小文件大小)"""
88
+ files, error = _get_images(input_dir)
89
+ if error:
90
+ print(f"错误: {error}")
91
+ return False
92
+
93
+ if output_dir:
94
+ out_path = Path(output_dir)
95
+ else:
96
+ out_path = Path(input_dir) / f"compressed_q{quality}"
97
+ out_path.mkdir(parents=True, exist_ok=True)
98
+
99
+ if not 1 <= quality <= 100:
100
+ print("错误:质量值必须在 1-100 之间")
101
+ return False
102
+
103
+ print(f"找到 {len(files)} 个图片文件,压缩质量: {quality}%")
104
+ success = 0
105
+ total_saved = 0
106
+
107
+ for f in files:
108
+ try:
109
+ img = Image.open(f)
110
+ original_size = f.stat().st_size
111
+
112
+ out_file = out_path / f.name
113
+ format_map = {'.jpg': 'JPEG', '.jpeg': 'JPEG', '.png': 'PNG', '.webp': 'WEBP', '.bmp': 'BMP', '.tiff': 'TIFF'}
114
+ fmt = format_map.get(f.suffix.lower(), 'JPEG')
115
+
116
+ if fmt == 'JPEG':
117
+ if img.mode in ('RGBA', 'P'):
118
+ img = img.convert('RGB')
119
+ img.save(out_file, format=fmt, quality=quality, optimize=True)
120
+ elif fmt == 'PNG':
121
+ img.save(out_file, format=fmt, optimize=True)
122
+ else:
123
+ img.save(out_file, format=fmt)
124
+
125
+ new_size = out_file.stat().st_size
126
+ saved = original_size - new_size
127
+ total_saved += saved
128
+ pct = ((original_size - new_size) / original_size * 100) if original_size > 0 else 0
129
+
130
+ print(f" ✓ {f.name} ({original_size//1024}KB → {new_size//1024}KB, 节省 {pct:.0f}%)")
131
+ success += 1
132
+ except Exception as e:
133
+ print(f" ✗ {f.name} 处理失败: {e}")
134
+
135
+ print(f"\n完成!成功处理 {success}/{len(files)} 个文件")
136
+ print(f"总节省空间: {total_saved / 1024:.1f} KB")
137
+ print(f"输出目录: {out_path}")
138
+ return success > 0
139
+
140
+
141
+ def image_info(input_dir):
142
+ """查看图片信息"""
143
+ files, error = _get_images(input_dir)
144
+ if error:
145
+ print(f"错误: {error}")
146
+ return False
147
+
148
+ print(f"{'文件名':30s} {'格式':8s} {'尺寸':14s} {'大小':10s}")
149
+ print("-" * 62)
150
+
151
+ total_size = 0
152
+ for f in files:
153
+ try:
154
+ img = Image.open(f)
155
+ size = f.stat().st_size
156
+ total_size += size
157
+ dim = f"{img.size[0]}x{img.size[1]}"
158
+ print(f"{f.name:30s} {img.format:8s} {dim:14s} {size//1024:4d}KB")
159
+ except Exception as e:
160
+ print(f"{f.name:30s} {'ERROR':8s}")
161
+
162
+ print("-" * 62)
163
+ print(f"{'总计':30s} {len(files):3d} 个文件{'':8s} {total_size//1024:4d}KB")
164
+ return True
165
+
166
+
167
+ def _show_promotion():
168
+ print("\n" + "=" * 55)
169
+ print(" 🔧 img-resize-kit - 图片批量缩放与压缩工具")
170
+ print(" 📦 pip install img-resize-kit")
171
+ print(" ☕ 如果帮到了您,欢迎打赏支持:")
172
+ print(" USDT(TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa")
173
+ print(" ⭐ https://github.com/BoiledSaltedDuck/img-resize-kit")
174
+ print("=" * 55)
175
+
176
+
177
+ def main():
178
+ if len(sys.argv) < 2:
179
+ print("用法:")
180
+ print(" 缩放图片: img-resize resize [输入目录] [宽度] [高度] [输出目录(可选)]")
181
+ print(" 压缩图片: img-resize compress [输入目录] [质量1-100] [输出目录(可选)]")
182
+ print(" 查看信息: img-resize info [输入目录]")
183
+ print()
184
+ print("示例:")
185
+ print(" img-resize resize ./图片/ 800 600 ./输出/")
186
+ print(" img-resize compress ./图片/ 80")
187
+ print(" img-resize info ./图片/")
188
+ sys.exit(1)
189
+
190
+ command = sys.argv[1].lower()
191
+
192
+ if command == "resize":
193
+ if len(sys.argv) < 5:
194
+ print("用法: img-resize resize [输入目录] [宽度] [高度] [输出目录(可选)]")
195
+ sys.exit(1)
196
+ try:
197
+ width = int(sys.argv[3])
198
+ height = int(sys.argv[4])
199
+ except ValueError:
200
+ print("错误:宽度和高度必须为整数")
201
+ sys.exit(1)
202
+ output = sys.argv[5] if len(sys.argv) > 5 else None
203
+ success = resize_images(sys.argv[2], width, height, output)
204
+
205
+ elif command == "compress":
206
+ if len(sys.argv) < 4:
207
+ print("用法: img-resize compress [输入目录] [质量1-100] [输出目录(可选)]")
208
+ sys.exit(1)
209
+ try:
210
+ quality = int(sys.argv[3])
211
+ except ValueError:
212
+ print("错误:质量必须为整数(1-100)")
213
+ sys.exit(1)
214
+ output = sys.argv[4] if len(sys.argv) > 4 else None
215
+ success = compress_images(sys.argv[2], quality, output)
216
+
217
+ elif command == "info":
218
+ if len(sys.argv) < 3:
219
+ print("用法: img-resize info [输入目录]")
220
+ sys.exit(1)
221
+ success = image_info(sys.argv[2])
222
+
223
+ else:
224
+ print(f"错误:不支持的命令 '{command}',仅支持 resize/compress/info")
225
+ sys.exit(1)
226
+
227
+ if success:
228
+ _show_promotion()
229
+ sys.exit(0 if success else 1)
230
+
231
+
232
+ if __name__ == "__main__":
233
+ main()
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: img-resize-kit
3
+ Version: 1.0.0
4
+ Summary: 图片批量缩放与压缩工具 - 批量调整图片尺寸、压缩图片大小、查看图片信息
5
+ Author-email: BoiledSaltedDuck <tools@office-tools.pro>
6
+ License: MIT
7
+ Keywords: image,resize,compress,图片缩放,图片压缩,batch
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Multimedia :: Graphics
12
+ Classifier: Topic :: Utilities
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: Pillow>=9.0
17
+ Dynamic: license-file
18
+
19
+ # img-resize-kit 图片批量缩放与压缩工具
20
+
21
+ [![PyPI version](https://img.shields.io/pypi/v/img-resize-kit)](https://pypi.org/project/img-resize-kit/)
22
+ [![Downloads](https://img.shields.io/pypi/dm/img-resize-kit)](https://pypi.org/project/img-resize-kit/)
23
+ [![License](https://img.shields.io/pypi/l/img-resize-kit)](https://github.com/BoiledSaltedDuck/img-resize-kit/blob/main/LICENSE)
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install img-resize-kit
29
+ ```
30
+
31
+ ## 用法
32
+
33
+ ```bash
34
+ # 批量缩放图片(保持宽高比)
35
+ img-resize resize ./图片/ 800 600 ./输出/
36
+
37
+ # 批量压缩图片
38
+ img-resize compress ./图片/ 80
39
+
40
+ # 查看图片信息
41
+ img-resize info ./图片/
42
+ ```
43
+
44
+ ## 功能
45
+
46
+ ### 缩放 (resize)
47
+ - 批量调整图片到指定尺寸
48
+ - 默认保持宽高比
49
+ - 使用 LANCZOS 高质量重采样算法
50
+
51
+ ### 压缩 (compress)
52
+ - 批量压缩 JPEG 图片(调整质量参数)
53
+ - PNG 图片自动优化
54
+ - 显示压缩前后的文件大小对比
55
+
56
+ ### 信息 (info)
57
+ - 扫描目录中所有图片
58
+ - 显示格式、尺寸、文件大小
59
+
60
+ ## 支持
61
+
62
+ 如果 img-resize-kit 帮到了您,欢迎打赏支持:
63
+
64
+ ```
65
+ USDT (TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa
66
+ ```
67
+
68
+ 您的支持是开源项目持续发展的动力 ❤️
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ img_resize/__init__.py
5
+ img_resize/resizer.py
6
+ img_resize_kit.egg-info/PKG-INFO
7
+ img_resize_kit.egg-info/SOURCES.txt
8
+ img_resize_kit.egg-info/dependency_links.txt
9
+ img_resize_kit.egg-info/entry_points.txt
10
+ img_resize_kit.egg-info/requires.txt
11
+ img_resize_kit.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ img-resize = img_resize.resizer:main
@@ -0,0 +1 @@
1
+ Pillow>=9.0
@@ -0,0 +1 @@
1
+ img_resize
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "img-resize-kit"
7
+ version = "1.0.0"
8
+ description = "图片批量缩放与压缩工具 - 批量调整图片尺寸、压缩图片大小、查看图片信息"
9
+ readme = "README.md"
10
+ authors = [
11
+ {name = "BoiledSaltedDuck", email = "tools@office-tools.pro"}
12
+ ]
13
+ license = {text = "MIT"}
14
+ keywords = ["image", "resize", "compress", "图片缩放", "图片压缩", "batch"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: Multimedia :: Graphics",
20
+ "Topic :: Utilities",
21
+ ]
22
+ requires-python = ">=3.7"
23
+ dependencies = [
24
+ "Pillow>=9.0",
25
+ ]
26
+
27
+ [project.scripts]
28
+ img-resize = "img_resize.resizer:main"
29
+
30
+ [tool.setuptools.packages.find]
31
+ include = ["img_resize*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+