使用魔杖图像+Python2.7修剪白色sp

2024-04-23 10:48:19 发布

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

有没有一个好的方法来修剪由PDF生成的jpg周围的白色边框魔杖图像,还是应该使用其他软件包?jpg的边框颜色也不同。下面的代码为每个部件生成图像文件。只是不知道如何修剪空白

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'))

我的系统:Ubuntu16上的Python2.7

提前谢谢你!在


Tags: 方法图像imageimgpdfaswithpage
1条回答
网友
1楼 · 发布于 2024-04-23 10:48:19

应该有一个^{}方法来完成此操作。在

>>> 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

相关问题 更多 >