Написал вот такой метод. Аргументом передается картинка в бинарном виде.
def picture_overlay(photo):
foreground = Image.open(photo, "r")
foreground = foreground.convert('RGBA')
background = Image.open(r"big.jpg")
background = background.convert('RGBA')
bwidth, bheight = background.size[0], background.size[1]
fwidth, fheight = foreground.size[0], foreground.size[1]
x, y = int((bwidth / 2) - (fwidth / 2)), int((bheight / 2) - (fheight / 2)) # центрирование
background.paste(foreground, (x, y), mask=foreground)
return background
Ошибка
File "C:\Users\s41bl\PycharmProjects\birthday_project\UnitePic.py", line 7, in picture_overlay
foreground = Image.open(photo, "r")
File "C:\Users\s41bl\PycharmProjects\birthday_project\venv\lib\site-packages\PIL\Image.py", line 2634, in open
fp = builtins.open(filename, "rb")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Process finished with exit code 1