【问题标题】:Using wand.image + python 2.7 to trim white space使用 wand.image + python 2.7 修剪空白
【发布时间】:2018-03-29 01:07:32
【问题描述】:

有没有一种好方法可以使用 wand.image 修剪从 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'))

我的系统:ubuntu 16 上的 python 2.7

提前谢谢你!

【问题讨论】:

  • 空白是否总是可以用矩形表示?
  • 好问题。页面可能有弯曲的边缘。
  • 如果你不关心大小,你可以只检测 blob 并获取边界框的总数。
  • 谢谢,尺寸无关紧要(不需要完全相同),所以你是对的,我需要从顶部、底部等找出边界。关于如何这样做?

标签: python image-processing wand


【解决方案1】:

应该有一个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")

【讨论】:

    猜你喜欢
    • 2013-10-27
    • 2012-11-23
    • 2018-08-26
    • 2017-03-16
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 2010-11-14
    • 2011-05-07
    相关资源
    最近更新 更多