Skip to content

Commit f6f0199

Browse files
committed
1 add prompt
1 parent a70295c commit f6f0199

2 files changed

Lines changed: 465 additions & 0 deletions

File tree

prompt/img-compression-guide.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 图片压缩指南
2+
3+
## PNG 转 JPEG
4+
5+
适用场景:文档插图(示意图、流程图等),非纯色/透明背景图片。
6+
7+
### 工具
8+
9+
使用 Python PIL (Pillow):
10+
11+
```python
12+
from PIL import Image
13+
import os
14+
15+
files = ['xxx.png', 'yyy.png']
16+
17+
for f in files:
18+
out = f.replace('.png', '.jpg')
19+
img = Image.open(f).convert('RGB')
20+
img.save(out, 'JPEG', quality=85, optimize=True)
21+
orig = os.path.getsize(f) / 1024
22+
new = os.path.getsize(out) / 1024
23+
print(f"{f}: {orig:.0f}KB → {out}: {new:.0f}KB (saved {orig-new:.0f}KB)")
24+
```
25+
26+
### 参数说明
27+
28+
- `quality=85`:文档插图用此质量足够清晰,文件体积适中
29+
- `convert('RGB')`:移除 PNG 透明通道,转换为标准 JPEG
30+
- `optimize=True`:启用 JPEG 优化编码,进一步减小体积
31+
32+
### 压缩效果(参考)
33+
34+
| 文件 | 原大小 | 压缩后 | 节省 |
35+
|------|--------|--------|------|
36+
| catalog-db-tbl.png | 2.1MB | 191KB | 91% |
37+
| columnar-storage.png | 1.9MB | 231KB | 88% |
38+
| mpp.png | 2.2MB | 240KB | 89% |
39+
| partition-bucket.png | 1.5MB | 186KB | 88% |
40+
| runtime-filter.png | 1.9MB | 265KB | 86% |
41+
42+
### 注意事项
43+
44+
- 透明背景图片不适合转 JPEG(会变成白底)
45+
- 纯色/截图类图片建议用 PNG + tinypng.com 压缩

0 commit comments

Comments
 (0)