脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python实现碑帖图片横向拼接

python实现碑帖图片横向拼接

2021-09-16 00:12傅佑 Python

这篇文章主要为大家详细介绍了python实现碑帖图片横向拼接,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了python实现碑帖图片横向拼接的具体代码,供大家参考,具体内容如下

一、原图

python实现碑帖图片横向拼接

二、拼接效果(按照书法的从右往左顺序)

python实现碑帖图片横向拼接

三、python代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#collection of calligraphy characters
import os
from pil import image
 
if __name__ == '__main__':
  im_list = []
  path = r"c:\users\administrator\desktop\724"
  pathlist = os.listdir(path)
  for fn in reversed(pathlist):
    if fn.endswith('.jpg'):
      im_list.append(image.open(path + os.sep + fn))
 
  width = 0
  height = 0
  for img in im_list:
    # 单幅图像尺寸
    w, h = img.size
    width += w
    # 取最大的宽度作为拼接图的宽度
    height= max(height, h)
 
  # 创建空白长图
  result = image.new(im_list[0].mode, (width, height), 0xffffff)
  # 拼接图片
  width = 0
  for img in im_list:
    w, h = img.size
    # 图片水平居中
    result.paste(img, box=(width,round(height / 2 - h / 2)))
    width += w
  # 保存图片
  result.save(r'c:\users\administrator\desktop\拼接长图.jpg')

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_43756157/article/details/114386206

延伸 · 阅读

精彩推荐