0

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!

damores
  • 2,251
  • 2
  • 18
  • 31
FlyingZebra1
  • 1,285
  • 1
  • 18
  • 28

1 Answers1

3

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

emcconville
  • 23,800
  • 4
  • 50
  • 66