python实现图片横向和纵向拼接-创新互联
本文实例为大家分享了python实现图片横向和纵向拼接的具体代码,供大家参考,具体内容如下
站在用户的角度思考问题,与客户深入沟通,找到乌鲁木齐网站设计与乌鲁木齐网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、网站设计、企业官网、英文网站、手机端网站、网站推广、域名注册、虚拟主机、企业邮箱。业务覆盖乌鲁木齐地区。直接上代码:
# -*- coding:utf-8 -*- __author__ = 'ShawDa' from PIL import Image def join(png1, png2, flag='horizontal'): """ :param png1: path :param png2: path :param flag: horizontal or vertical :return: """ img1, img2 = Image.open(png1), Image.open(png2) size1, size2 = img1.size, img2.size if flag == 'horizontal': joint = Image.new('RGB', (size1[0]+size2[0], size1[1])) loc1, loc2 = (0, 0), (size1[0], 0) joint.paste(img1, loc1) joint.paste(img2, loc2) joint.save('horizontal.png') elif flag == 'vertical': joint = Image.new('RGB', (size1[0], size1[1]+size2[1])) loc1, loc2 = (0, 0), (0, size1[1]) joint.paste(img1, loc1) joint.paste(img2, loc2) joint.save('vertical.png') if __name__ == '__main__': png = 'lena.png' join(png, png) join(png, png, flag='vertical')
网站题目:python实现图片横向和纵向拼接-创新互联
当前网址:http://scyanting.com/article/dphsos.html