So I'm trying to build a script with the Pillow module that will put a border around a selected image so all photos I upload will have the same minimum border width. However, contrarcy to the PIL documentation, I keep getting the error: "images do not match". It was my understanding that the only prerequisite to paste onto another image was the number of bands?
Below is my code. You can see in my comments near the bottom that I've even compared two identically generated images. If I change either of the first two arguments, I receive the error.
import Image as img
from photos import pick_asset, get_image
size = (1080, 1080)
max = size[0]*.85
og = pick_asset(multi=True)
for pic in og:
shortest = 1
longest = 1
pic = pic.get_image()
pic.convert('RGB')
pic_size = list(pic.size)
# creating the background
border = img.new('RGB', size, 'white')
border2 = img.new('RGB', (400,400), 'white')
# determing which side is longest
if pic_size[0] > pic_size[1]:
longest = pic_size[0]
shortest = pic_size[1]
if pic_size[0] < pic_size[1]:
longest = pic_size[1]
shortest = pic_size[0]
# resizing as needed
divisor = shortest/longest
multiplier = longest/shortest
x = round(pic_size[0]*divisor)
y = round(pic_size[1]*divisor)
x2 = round(pic_size[0]*multiplier)
y2 = round(pic_size[1]*multiplier)
if longest > max:
# pic too big. scale pic down
pic.resize((x, y))
if longest < max:
# pic too small. scale down bg
border.resize((x2, y2))
new_pic = pic.copy()
#final_pic = border.paste(pic)
#print(str(pic_size[0]) + ", " + str(pic_size[1]))
#final_pic = border.paste(border2)
#final.save()
`