Python realizes horizontal and vertical splicing of pictures

The examples in this article share the specific code of python to realize horizontal and vertical splicing of pictures for your reference. The specific content is as follows

Directly on the code:

# - *- 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')

result:

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python realizes horizontal and vertical splicing of pictures
Python implements horizontal stitching of pictures
Python realizes stitching pictures
Magic methods and uses of Python
Python implements string and number splicing
Mongodb and python interaction of python crawler
Python implementation of intersection and IOU tutorial
Python realizes batch modification of file names
Example of python calculating derivative and plotting
python3 realizes the function of mask drawing
Python- crawl all pictures of a station
The difference between the syntax of java and python
Python realizes the development of student management system
The meaning and usage of lists in python
Python uses PIL to cut and stitch pictures
7 features of Python3.9
Python and Go
A brief summary of the difference between Python2 and Python3
Solve the problem of python compiling and installing ssl
Installation and use of GDAL in Python under Ubuntu
Example of how to automatically download pictures in python