如何使用魔杖扭曲图像

2024-06-18

我正在尝试做同样的事情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

expected result Expected result

background image Background image

源图像

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(使用前将#替换为@)

如何使用魔杖扭曲图像 的相关文章

随机推荐

  • 在 Mac OS Sierra 上使用 brew 安装节点失败

    我正在尝试在 macOS Sierra 上使用自制程序安装节点 我跑 brew install node 看似成功安装后 我在尝试运行时得到以下信息node dyld Library not loaded usr local opt icu
  • Linux 上的静态 Qt5 构建:部署时如何处理字体?

    我使用这些配置选项创建了 Qt 5 2 0 库的静态版本 Ubuntu 12 04 开源 确认许可 force pkg config 发布 静止的 前缀 home juzzlin qt5 无icu opengl桌面 无油嘴滑舌 辅助功能 n
  • 如何使用系统凭据自动登录网站?

    我需要为 Intranet 用户开发一个 Web 应用程序 我不希望他们每次访问该网站时都输入登录凭据 它应该从系统用户名和密码自动加载 即 如果他们拥有有效的系统用户名和密码 他们应该能够登录应用程序 我正在使用Java 如何满足这个要求
  • 如何水平居中条形图注释

    我正在创建一个像这样的条形图 gender M F numbers males females bars plt bar gender numbers width 0 1 bottom None align center data None
  • 在 Docker 中保护私有 PyPi 的凭据

    我正在构建 Docker 映像 需要运行 pip install 与带有凭据的私有 PyPi 保护凭证的最佳方法是什么 即使我删除它们 使用各种文件配置选项 pip conf requirements txt netrc 仍然是一个漏洞 因
  • Camera2basic 应用程序,在 Android 6.0 LGG3 中具有非常暗的预览

    新的 API 也许只在 LG G3 上 似乎发生了一些变化 我在用着示例代码 https github com googlesamples android Camera2Basic 在我的 Nexus 4 上 代码运行完美 但在更新到 An
  • 从按日期时间排序的 MySQL 表中获取用户的最后一个条目

    我有一张看起来像这样的桌子 USERNAME DATA DATETIME Jhon text1 2010 06 01 16 29 43 Mike text2 2010 06 01 16 29 22 Silver text3 2010 05
  • 即使使用 MathContext 也会出现非终止小数错误

    我正在编写代码来实现这个算法 但是 即使使用 MathContext 1000 我也会收到此错误 Exception in thread main java lang ArithmeticException Non terminating
  • 有没有办法更改 JDialog 的所有者?

    我有一个非常具体的问题 我想知道是否有办法更改 JDialog 的所有者 可以使用构造函数设置 我想不存在 官方 的可能性 除了黑客攻击 但我想确保我没有错过任何东西 关于该主题的任何想法或提示都会有所帮助 谢谢 如果您的问题是如何在应用程
  • 仅当设备打开并且小部件在主屏幕上可见时更新小部件

    据我了解有关 Widgets 的官方文档 我有点困惑 标准 方法是定义一个BroadcastReceiver并以毫秒为单位定义更新频率 这种方式允许最小更新间隔为 30 分钟以节省电池电量 听起来很有道理 我发现阅读 Google 文档的
  • CKEDITOR - 如何添加永久 onclick 事件?

    我正在寻找一种使 CKEDITOR wysiwyg 内容具有交互性的方法 这意味着例如向特定元素添加一些 onclick 事件 我可以做这样的事情 CKEDITOR instances editor1 document getById so
  • 如何获得 Elixir 中每种类型的最小值和最大值

    如何获得 Elixir 中每种类型的最小值和最大值 例如整数 浮点数和字符串的最大可能长度 我知道在C中它的定义是limits h as INT MIN INT MAX等等 关于 Elixir 中这些类型的限制的文档在哪里 Elixir 实
  • 如何使用 SVG 形状进行图像裁剪?

    任何人都可以指导我如何使用 SVG 独特的形状制作 CSS 图像剪辑路径 有些人建议使用第三方插件 例如 SVG Injector 等 任何人都可以帮助我如何完成这项适用于所有浏览器的任务 我给出了一张示例图片以使其更好地理解 请检查下图
  • 使用 Internet Explorer 和 SSL 时如何启用自动完成功能?

    当以下两个条件都成立时 1 The page was delivered over HTTPS 2 The page was delivered with headers or a META tag that prevents cachin
  • Vim 搜索模式,如果出现则删除到行尾

    我正在尝试在文本文件中搜索特定模式 如果出现这种模式 则意味着该行的其余部分不需要 因此可以删除 我尝试过使用以下命令 但到目前为止还没有成功 s pattern d g pattern d 如果有人有任何建议 他们将不胜感激 would
  • 数据透视表错误 |无效的调用或过程

    我需要一些帮助来解决这个问题 我正在尝试创建一个数据透视表 从第一季度开始 在同一张表中包含一系列数据 第一个 if 语句在那里是因为最后一列并不总是包含标题 所以我将其包含在那里 我希望范围是动态的 因为所制作的表格的大小将根据工作表中数
  • 从 swift 数组创建张量

    这工作正常 import TensorFlow var t Tensor
  • “引擎”和“框架”有什么区别? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我听说这些术语似乎可以互换使用 所以我有点不清楚 请举出例子 这些术语和其他术语看起来确实非常相似 它们是从概念角度命名的 因此可以定
  • Valgrind 对未初始化的字节大喊大叫

    Valgrind 抛出了这个错误 11204 Syscall param write buf points to uninitialised byte s 11204 at 0x4109033 write in lib libc 2 13
  • 如何使用魔杖扭曲图像

    我正在尝试做同样的事情this https stackoverflow com questions 52090350 how to insert image in a mock up老问题但在python using wand 到目前为止我