简体   繁体   中英

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? Note, the jpg's are images, with varying colors @ borders. 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

thank you in advance!

There should be a Image.trim method to do this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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