用魔杖拼接图像,Python不会

2024-09-27 02:25:28 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想把一个图像拼接成两个,为此我写了这段代码。你知道吗

from wand.image import Image
from wand.display import display
with Image(filename="test.png") as im :
  im.trim(color=None,fuzz=0)
  x,y = im.size
  xh,yh = int(x/2),int(y/2)
  print(x,y,xh,yh)
  im1 = im[0:xh,0:y]
  print(im1.size)
  display(im1)

图像的大小是(1156242),因此拼接的图像应该是(578242),而不是(553235)。有人知道为什么吗?Here is the test image.


Tags: fromtest图像imageimportsizedisplaywand
1条回答
网友
1楼 · 发布于 2024-09-27 02:25:28

这就是使用wand.image.Image.trim的效果。只需要一个简单的“重新页面”。你知道吗

from wand.image import Image

with Image(filename="test.png") as im :
  im.trim(color=None,fuzz=0)
  im.reset_coords()  # <= Same as `-repage'
  x,y = im.size
  xh,yh = int(x/2),int(y/2)
  print(x,y,xh,yh)
  im1 = im[0:xh,0:y]
  print(im1.size)
  display(im1)

我现在手头没有文档链接,但是快速搜索ImageMagick的-repage命令行选项应该有助于描述这个过程。你知道吗

相关问题 更多 >

    热门问题