I am trying to use the getbbox
to crop a picture and then save it. However I keep on getting a certain error that I don't know how to fix.
The code:
import ImageOps
import Image
im=Image.open("b1.jpg")
invert_im = ImageOps.invert(im) # because the boundary is white so I convert it to black so I can crop the photo
im2 =invert_im.getbbox()
invert_im = ImageOps.invert(im2) # invert back
invert_im.save("b1_cropped.jpg")
The error I am receiving:
AttributeError: 'tuple' object has no attribute 'save'
Any ideas?
import ImageOps
import Image
im=Image.open("b1.jpg")
inverted = ImageOps.invert(im)
box = inverted.getbbox()
cropped_im = im.crop(box)
cropped_im.save("b1_cropped.jpg")
This should be the answer.
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.