img-convert-kit 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.
@@ -0,0 +1,4 @@
1
+ """img-convert-kit - 图片格式批量转换工具"""
2
+
3
+ __version__ = "1.0.0"
4
+ from . import converter
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ img-convert-kit - 图片格式批量转换工具
4
+ 功能:批量转换图片格式(jpg, png, webp, bmp, gif, tiff)
5
+ 用法:img-convert [输入目录] [目标格式] [输出目录]
6
+ img-convert ./图片/ webp ./输出/
7
+ """
8
+ import sys
9
+ import os
10
+ from pathlib import Path
11
+
12
+ try:
13
+ from PIL import Image
14
+ except ImportError:
15
+ print("正在安装 Pillow...")
16
+ import subprocess
17
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "Pillow", "-q"])
18
+ from PIL import Image
19
+
20
+ SUPPORTED_FORMATS = {"jpg", "jpeg", "png", "webp", "bmp", "gif", "tiff"}
21
+
22
+ def convert_images(input_dir, target_format, output_dir=None):
23
+ input_path = Path(input_dir)
24
+ if not input_path.exists():
25
+ print(f"错误:目录 {input_dir} 不存在")
26
+ return False
27
+
28
+ target_format = target_format.lower().replace(".", "")
29
+ if target_format not in SUPPORTED_FORMATS:
30
+ print(f"错误:不支持的格式 '{target_format}'")
31
+ print(f"支持的格式: {', '.join(sorted(SUPPORTED_FORMATS))}")
32
+ return False
33
+
34
+ if output_dir:
35
+ out_path = Path(output_dir)
36
+ else:
37
+ out_path = input_path / f"converted_{target_format}"
38
+ out_path.mkdir(exist_ok=True)
39
+
40
+ # 收集支持格式的图片
41
+ image_exts = {'.jpg', '.jpeg', '.png', '.webp', '.bmp', '.gif', '.tiff'}
42
+ image_files = []
43
+ for ext in image_exts:
44
+ image_files.extend(list(input_path.glob(f"*{ext}")) + list(input_path.glob(f"*{ext.upper()}")))
45
+
46
+ if not image_files:
47
+ print(f"错误:目录 {input_dir} 中没有找到支持的图片文件")
48
+ return False
49
+
50
+ # 排除源文件目录中已经是目标格式的文件(避免无意义转换)
51
+ image_files = [f for f in image_files if f.suffix.lower() != f".{target_format}"]
52
+
53
+ if not image_files:
54
+ print(f"所有文件已经是 {target_format} 格式,无需转换")
55
+ return False
56
+
57
+ print(f"找到 {len(image_files)} 个图片文件待转换")
58
+ success_count = 0
59
+
60
+ for f in sorted(image_files):
61
+ try:
62
+ img = Image.open(f)
63
+ out_name = f.stem + f".{target_format}"
64
+ out_file = out_path / out_name
65
+
66
+ # 特殊处理:GIF保存需要特殊参数
67
+ if target_format == "gif":
68
+ img = img.convert("P", palette=Image.ADAPTIVE)
69
+ img.save(out_file, format="GIF")
70
+ elif target_format == "jpg" or target_format == "jpeg":
71
+ if img.mode in ("RGBA", "P"):
72
+ img = img.convert("RGB")
73
+ img.save(out_file, format="JPEG", quality=95)
74
+ else:
75
+ img.save(out_file)
76
+
77
+ success_count += 1
78
+ print(f" ✓ {f.name} → {out_name}")
79
+ except Exception as e:
80
+ print(f" ✗ {f.name} 转换失败: {e}")
81
+
82
+ print(f"\n完成!成功转换 {success_count}/{len(image_files)} 个文件")
83
+ print(f"输出目录: {out_path}")
84
+ _show_promotion()
85
+ return success_count > 0
86
+
87
+ def _show_promotion():
88
+ print("\n" + "=" * 55)
89
+ print(" 🔧 img-convert-kit - 图片格式批量转换工具")
90
+ print(" 📦 pip install img-convert-kit")
91
+ print(" ☕ 如果帮到了您,欢迎打赏支持:")
92
+ print(" USDT(TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa")
93
+ print(" ⭐ https://github.com/BoiledSaltedDuck/img-convert-kit")
94
+ print("=" * 55)
95
+
96
+ def main():
97
+ if len(sys.argv) < 3:
98
+ print("用法: img-convert [输入目录] [目标格式] [输出目录(可选)]")
99
+ print("示例: img-convert ./图片/ webp ./输出/")
100
+ print(f"支持格式: {', '.join(sorted(SUPPORTED_FORMATS))}")
101
+ sys.exit(1)
102
+
103
+ input_dir = sys.argv[1]
104
+ target_format = sys.argv[2]
105
+ output_dir = sys.argv[3] if len(sys.argv) > 3 else None
106
+
107
+ success = convert_images(input_dir, target_format, output_dir)
108
+ sys.exit(0 if success else 1)
109
+
110
+ if __name__ == "__main__":
111
+ main()
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: img-convert-kit
3
+ Version: 1.0.0
4
+ Summary: 图片格式批量转换工具 - 支持jpg, png, webp, bmp, gif, tiff等格式互转
5
+ Author-email: BoiledSaltedDuck <tools@office-tools.pro>
6
+ License: MIT
7
+ Keywords: image,convert,format,图片转换,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 :: Graphics Conversion
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-convert-kit 图片格式批量转换工具
20
+
21
+ [![PyPI version](https://img.shields.io/pypi/v/img-convert-kit)](https://pypi.org/project/img-convert-kit/)
22
+ [![Downloads](https://img.shields.io/pypi/dm/img-convert-kit)](https://pypi.org/project/img-convert-kit/)
23
+ [![License](https://img.shields.io/pypi/l/img-convert-kit)](https://github.com/BoiledSaltedDuck/img-convert-kit/blob/main/LICENSE)
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install img-convert-kit
29
+ ```
30
+
31
+ ## 用法
32
+
33
+ 批量转换图片格式:
34
+
35
+ ```bash
36
+ # 将 ./图片/ 目录下所有图片转换为 webp 格式,输出到 ./输出/
37
+ img-convert ./图片/ webp ./输出/
38
+
39
+ # 使用默认输出目录(输入目录下的 converted_格式 子目录)
40
+ img-convert ./图片/ jpg
41
+ ```
42
+
43
+ ## 支持的格式
44
+
45
+ | 格式 | 说明 |
46
+ |------|------|
47
+ | jpg/jpeg | JPEG图像(质量95%) |
48
+ | png | PNG无损图像 |
49
+ | webp | WebP现代格式(体积更小) |
50
+ | bmp | BMP位图 |
51
+ | gif | GIF动图/静态图 |
52
+ | tiff | TIFF多页图像 |
53
+
54
+ ## 特点
55
+
56
+ - 一行命令批量转换
57
+ - 自动识别目录中所有图片
58
+ - 智能跳过已为目标格式的文件
59
+ - 支持大小写混用的扩展名
60
+ - 保持原始文件名
61
+
62
+ ## 支持
63
+
64
+ 如果 img-convert-kit 帮到了您,欢迎打赏支持:
65
+
66
+ ```
67
+ USDT (TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa
68
+ ```
69
+
70
+ 您的支持是开源项目持续发展的动力 ❤️
@@ -0,0 +1,8 @@
1
+ img_convert/__init__.py,sha256=fsz7W2T8AQos9COsUyCbZDd66EwvNvq5OklJyMYEsDI,102
2
+ img_convert/converter.py,sha256=V84As8P6CMw2T24iULJtP8a4h1rkPiITN9QmKwbhf2I,3943
3
+ img_convert_kit-1.0.0.dist-info/licenses/LICENSE,sha256=ebeGZOtiPvaMQ3VNAf6UiI3tLGbUxBaI6bXpZZwwjfE,1073
4
+ img_convert_kit-1.0.0.dist-info/METADATA,sha256=pOZz7JBLXjfEZ8b8deDSF57aOKE-jzZA2Nf_e5YNT_o,1986
5
+ img_convert_kit-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ img_convert_kit-1.0.0.dist-info/entry_points.txt,sha256=mJKmApN73N731U8UI46D24kP52mEbWd_LqdxU7POMVM,59
7
+ img_convert_kit-1.0.0.dist-info/top_level.txt,sha256=UCvHfbOG_v_bO275T_8hIw8nuIRFAD8zYwBv4_eOst8,12
8
+ img_convert_kit-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ img-convert = img_convert.converter:main
@@ -0,0 +1,21 @@
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 WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ img_convert