我正在尝试做同样的事情this https://stackoverflow.com/questions/52090350/how-to-insert-image-in-a-mock-up老问题但在python
using wand
.
到目前为止我已经做了以下事情:
from wand.image import Image
from wand.display import display
# Paths to your input images
background_path = 'background.png'
source_path = 'source.jpg'
output_path = 'output.jpg'
# Open the background image
with Image(filename=background_path) as background:
# Open the source image (source)
with Image(filename=source_path) as source:
# Define the distortion points
distortion_points = (
0, 0, 0, 0,
265, 0, 540, 85,
265, 333, 594, 426,
0, 333, 342, 446
)
# Apply the perspective distortion to the blank image
source.distort('perspective', distortion_points)
# Composite the background image onto the distorted source
background.composite(source, 317, 99)
# Save the resulting image
background.save(filename=output_path)
display(Image(filename='output.jpg'))
The flower
图像扭曲且像素未对齐。
知道如何仅在 python 中实现相同的效果吗?
EDIT:
这是目前的状态
current result
![Current result](https://i.stack.imgur.com/rTyoM.jpg)
expected result
![Expected result](https://i.stack.imgur.com/Yuwb3.jpg)
background image
![Background image](https://i.stack.imgur.com/QqRaQ.jpg)
源图像
Thanks
我认为你需要这样做更多:
#!/usr/bin/env python3
from wand.image import Image
from wand.display import display
# Paths to your input images
background_path = 'background.jpg'
source_path = 'source.jpg'
output_path = 'output.jpg'
# Open the background image
with Image(filename=background_path) as background:
# Open the source image (source)
with Image(filename=source_path) as source:
# Define the distortion points
distortion_points = (
0, 0, 317, 99,
265, 0, 540, 85,
265, 333, 594, 426,
0, 333, 342, 446
)
# See https://docs.wand-py.org/en/0.6.7/guide/distortion.html
source.virtual_pixel = 'transparent'
source.artifacts['distort:viewport'] = f'{background.width}x{background.height}+0+0'
# Apply the perspective distortion to the blank image
source.distort('perspective', distortion_points)
# Composite the distorted source onto the background
background.composite(source, 0, 0)
# Save the resulting image
background.save(filename=output_path)
display(Image(filename='output.jpg'))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)