fasdfsa commited on
Commit
a220423
·
1 Parent(s): c9e61d0

add 浅黄拟口蘑

Browse files
.vscode/launch.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Python Debugger: Current File",
6
+ "type": "debugpy",
7
+ "request": "launch",
8
+ "program": "${file}",
9
+ "console": "integratedTerminal"
10
+ }
11
+ ]
12
+ }
merge_images_vertical.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from pathlib import Path
5
+
6
+ try:
7
+ from PIL import Image
8
+ except ImportError as exc:
9
+ raise SystemExit(
10
+ "未安装 Pillow。请先运行: pip install pillow"
11
+ ) from exc
12
+
13
+
14
+ def merge_vertical(top_path: Path, bottom_path: Path, output_path: Path) -> None:
15
+ with Image.open(top_path) as top_img, Image.open(bottom_path) as bottom_img:
16
+ top = top_img.convert("RGB")
17
+ bottom = bottom_img.convert("RGB")
18
+
19
+ canvas_width = max(top.width, bottom.width)
20
+ canvas_height = top.height + bottom.height
21
+
22
+ merged = Image.new("RGB", (canvas_width, canvas_height), "white")
23
+ top_x = (canvas_width - top.width) // 2
24
+ bottom_x = (canvas_width - bottom.width) // 2
25
+
26
+ merged.paste(top, (top_x, 0))
27
+ merged.paste(bottom, (bottom_x, top.height))
28
+ merged.save(output_path, quality=95)
29
+
30
+
31
+ def main() -> None:
32
+ parser = argparse.ArgumentParser(description="纵向合并两张图片,上图在前,下图在后。")
33
+ parser.add_argument(
34
+ "--top",
35
+ default="浅黄拟口蘑01.jpg",
36
+ help="上方图片路径,默认: 浅黄拟口蘑01.jpg",
37
+ )
38
+ parser.add_argument(
39
+ "--bottom",
40
+ default="浅黄拟口蘑02.jpg",
41
+ help="下方图片路径,默认: 浅黄拟口蘑02.jpg",
42
+ )
43
+ parser.add_argument(
44
+ "--output",
45
+ default="浅黄拟口蘑_合并.jpg",
46
+ help="输出图片路径,默认: 浅黄拟口蘑_合并.jpg",
47
+ )
48
+ args = parser.parse_args()
49
+
50
+ top_path = Path(args.top)
51
+ bottom_path = Path(args.bottom)
52
+ output_path = Path(args.output)
53
+
54
+ if not top_path.exists():
55
+ raise SystemExit(f"找不到上方图片: {top_path}")
56
+ if not bottom_path.exists():
57
+ raise SystemExit(f"找不到下方图片: {bottom_path}")
58
+
59
+ merge_vertical(top_path, bottom_path, output_path)
60
+ print(f"已生成: {output_path.resolve()}")
61
+
62
+
63
+ if __name__ == "__main__":
64
+ main()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pillow
有毒_浅黄拟口蘑.jpg ADDED

Git LFS Details

  • SHA256: 0e491cb366a88cb35b58e9f19985e5d201892db630c9b341138e23c975e877b3
  • Pointer size: 131 Bytes
  • Size of remote file: 705 kB