img-convert-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.
- img_convert_kit-1.0.0/LICENSE +21 -0
- img_convert_kit-1.0.0/PKG-INFO +70 -0
- img_convert_kit-1.0.0/README.md +52 -0
- img_convert_kit-1.0.0/img_convert/__init__.py +4 -0
- img_convert_kit-1.0.0/img_convert/converter.py +111 -0
- img_convert_kit-1.0.0/img_convert_kit.egg-info/PKG-INFO +70 -0
- img_convert_kit-1.0.0/img_convert_kit.egg-info/SOURCES.txt +11 -0
- img_convert_kit-1.0.0/img_convert_kit.egg-info/dependency_links.txt +1 -0
- img_convert_kit-1.0.0/img_convert_kit.egg-info/entry_points.txt +2 -0
- img_convert_kit-1.0.0/img_convert_kit.egg-info/requires.txt +1 -0
- img_convert_kit-1.0.0/img_convert_kit.egg-info/top_level.txt +1 -0
- img_convert_kit-1.0.0/pyproject.toml +31 -0
- img_convert_kit-1.0.0/setup.cfg +4 -0
|
@@ -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,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
|
+
[](https://pypi.org/project/img-convert-kit/)
|
|
22
|
+
[](https://pypi.org/project/img-convert-kit/)
|
|
23
|
+
[](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,52 @@
|
|
|
1
|
+
# img-convert-kit 图片格式批量转换工具
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/img-convert-kit/)
|
|
4
|
+
[](https://pypi.org/project/img-convert-kit/)
|
|
5
|
+
[](https://github.com/BoiledSaltedDuck/img-convert-kit/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install img-convert-kit
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 用法
|
|
14
|
+
|
|
15
|
+
批量转换图片格式:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 将 ./图片/ 目录下所有图片转换为 webp 格式,输出到 ./输出/
|
|
19
|
+
img-convert ./图片/ webp ./输出/
|
|
20
|
+
|
|
21
|
+
# 使用默认输出目录(输入目录下的 converted_格式 子目录)
|
|
22
|
+
img-convert ./图片/ jpg
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 支持的格式
|
|
26
|
+
|
|
27
|
+
| 格式 | 说明 |
|
|
28
|
+
|------|------|
|
|
29
|
+
| jpg/jpeg | JPEG图像(质量95%) |
|
|
30
|
+
| png | PNG无损图像 |
|
|
31
|
+
| webp | WebP现代格式(体积更小) |
|
|
32
|
+
| bmp | BMP位图 |
|
|
33
|
+
| gif | GIF动图/静态图 |
|
|
34
|
+
| tiff | TIFF多页图像 |
|
|
35
|
+
|
|
36
|
+
## 特点
|
|
37
|
+
|
|
38
|
+
- 一行命令批量转换
|
|
39
|
+
- 自动识别目录中所有图片
|
|
40
|
+
- 智能跳过已为目标格式的文件
|
|
41
|
+
- 支持大小写混用的扩展名
|
|
42
|
+
- 保持原始文件名
|
|
43
|
+
|
|
44
|
+
## 支持
|
|
45
|
+
|
|
46
|
+
如果 img-convert-kit 帮到了您,欢迎打赏支持:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
USDT (TRC20): TMPQygMkv42QPeyYnkxMkPwsqs7udbD2Aa
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
您的支持是开源项目持续发展的动力 ❤️
|
|
@@ -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
|
+
[](https://pypi.org/project/img-convert-kit/)
|
|
22
|
+
[](https://pypi.org/project/img-convert-kit/)
|
|
23
|
+
[](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,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
img_convert/__init__.py
|
|
5
|
+
img_convert/converter.py
|
|
6
|
+
img_convert_kit.egg-info/PKG-INFO
|
|
7
|
+
img_convert_kit.egg-info/SOURCES.txt
|
|
8
|
+
img_convert_kit.egg-info/dependency_links.txt
|
|
9
|
+
img_convert_kit.egg-info/entry_points.txt
|
|
10
|
+
img_convert_kit.egg-info/requires.txt
|
|
11
|
+
img_convert_kit.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Pillow>=9.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
img_convert
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "img-convert-kit"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "图片格式批量转换工具 - 支持jpg, png, webp, bmp, gif, tiff等格式互转"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "BoiledSaltedDuck", email = "tools@office-tools.pro"}
|
|
12
|
+
]
|
|
13
|
+
license = {text = "MIT"}
|
|
14
|
+
keywords = ["image", "convert", "format", "图片转换", "batch"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
|
20
|
+
"Topic :: Utilities",
|
|
21
|
+
]
|
|
22
|
+
requires-python = ">=3.7"
|
|
23
|
+
dependencies = [
|
|
24
|
+
"Pillow>=9.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
img-convert = "img_convert.converter:main"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
include = ["img_convert*"]
|