简体   繁体   English

Python魔杖从修剪中偏移

[英]Python Wand get Offset from Trim

I'm using Wand in Python for manipulating my images. 我在Python中使用魔杖操纵图像。 I'm using the .trim() function to auto-crop these images. 我正在使用.trim()函数自动裁剪这些图像。

The resulting image gives me the new size, obviously. 显然,生成的图像为我提供了新的尺寸。 But I can't figure out how to get the offset from the original image. 但是我不知道如何获得原始图像的偏移量。

The documentation is pretty sparse. 该文档非常稀疏。

In Imagemagick, you can use :info and you get the offset for trim (and the new size). 在Imagemagick中,您可以使用:info,并获得修剪的偏移量(以及新的尺寸)。

Is there a way to get the offset information using Wand? 有没有办法使用魔杖来获取偏移量信息?

Use wand.image.Image.page which will return the size + offset. 使用wand.image.Image.page将返回大小+偏移量。

with Image(filename="input.png") as img:
    img.trim()
    offset = img.page[2:]  # => (x, y)

There's also page_x & page_y properties introduced in version 0.4.3. 在版本0.4.3中还引入了page_xpage_y属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM