уф! Я понял это, используя этот полезный ответ на Слияние исправленного в перспективе изображения с прозрачным фоновым шаблоном изображения с помощью PILLOW [PIL, Python]
Пока вы используете QUAD для go с quadrilateral
для rectangle
, вы можете использовать перспективу для go возврата от rectangle
до quadrilateral
#!/usr/bin/env python3
from itertools import chain
from wand.color import Color
from wand.image import Image
with Image(filename='image2') as cover, Image(filename='image3') as template:
w, h = cover.size
cover.virtual_pixel = 'transparent'
source_points = (
(0, 0),
(w, 0),
(w, h),
(0, h)
)
destination_points = (
(628+78.37203406, 35.24937345),
(628+577.65062655, 62.72203406),
(628+550.17796594, 562.00062655),
(628+50.89937345, 534.52796594)
)
order = chain.from_iterable(zip(source_points, destination_points))
arguments = list(chain.from_iterable(order))
cover.distort('perspective', arguments)
# Overlay cover onto template and save
template.composite(cover,left=0,top=0)
template.save(filename='result.png')