-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcatenate jpeg images
33 lines (25 loc) · 961 Bytes
/
Concatenate jpeg images
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
33
from PIL import Image
im1 = Image.open('filepath_jpegImage1')
im2 = Image.open('filepath_jpegImage2')
im3 = Image.open('filepath_jpegImage3')
im4 = Image.open('filepath_jpegImage4')
def get_concat_h(im1, im2):
dst = Image.new('RGB', (im1.width + im2.width, im1.height))
dst.paste(im1, (0, 0))
dst.paste(im2, (im1.width, 0))
return dst
def get_concat_h(im3, im4):
dst = Image.new('RGB', (im3.width + im4.width, im3.height))
dst.paste(im3, (0, 0))
dst.paste(im4, (im3.width, 0))
return dst
get_concat_h(im1, im2).save('concatenatedimage1_2.jpg')
get_concat_h(im3, im4).save('concatenatedimage3_4.jpg')
im5 = Image.open('concatenatedimage1_2.jpg')
im6 = Image.open('concatenatedimage3_4.jpg')
def get_concat_v(im5, im6):
dst = Image.new('RGB', (im5.width, im5.height + im6.height))
dst.paste(im5, (0, 0))
dst.paste(im6, (0, im5.height))
return dst
get_concat_v(im5, im6).save('concatenatedimage1_2_3_4.jpg')