The examples in this article share the specific code of python to realize horizontal stitching of pictures for your reference. The specific content is as follows
import os
from PIL import Image
# The size of a single picture is 150*150
UNIT_SIZE =150
TARGET_WIDTH =5* UNIT_SIZE
path ="The address of the folder where pictures are stored"
images =[]
imagefile =[]
# Store all picture file names
for root, dirs, files in os.walk(path):for f in files:
images.append(f)
# I am here to stitch five pictures horizontally
for i inrange(5):
imagefile.append(path+'/'+images[i])
target = Image.new('RGB',(TARGET_WIDTH, UNIT_SIZE))
left =0
right = UNIT_SIZE
for image in imagefile:
# print(image)
# Copy the existing picture to the new above parameters are picture file and copy location(Upper left corner,Bottom right corner)
target.paste(Image.open(image),(left,0, right, UNIT_SIZE))
left += UNIT_SIZE
right += UNIT_SIZE
# Picture quality 0~100
quantity_value =100
target.save(path+'/end.jpg', quantity = quantity_value)
Picture effect achieved (picture from unsplash)
This article has been included in the topic "Python Image Processing Operations", welcome to click to learn more exciting content.
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts