简体   繁体   English

使用wand.image + python 2.7修剪空白

[英]Using wand.image + python 2.7 to trim white space

Is there a good way to trim white borders around jpgs generated from a PDF using wand.image, or should I be using another package? 是否可以使用wand.image修剪PDF生成的jpg周围的白色边框,还是我应该使用其他软件包? Note, the jpg's are images, with varying colors @ borders. 请注意,jpg是带有@边框的不同颜色的图像。 Code below generates the image files for each part. 下面的代码为每个零件生成图像文件。 Just have no clue how to trim out the white space 只是不知道如何修剪空白

from wand.image import Image
f = "my_pdf.pdf"
with Image(file=f, resolution=72) as document:
    for page_number, page in enumerate(document.sequence):
        with Image(page) as img:
            img.compression_quality = 70
            bytes_io_file = BytesIO(img.make_blob('JPEG'))

my system: python 2.7 on ubuntu 16 我的系统:Ubuntu 16上的python 2.7

thank you in advance! 先感谢您!

There should be a Image.trim method to do this. 应该有一个Image.trim方法来执行此操作。

>>> from wand.image import Image
>>> from wand.color import Color
>>> with Image(filename="logo:") as img:
...   img.trim(Color("WHITE"))
...   img.save(filename="output.png")

output.png

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

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