mercredi 8 avril 2015

Python 3/PNG won't autocrop using image.getbbox()

I've been trying to get thisimage I want to cropimage to automatically crop to the smallest size possible, removing the transparent bits around it. I can't just crop this image myself manually, as more things will be added on the image like this image I want to crop as well.


I've been using this code:



from PIL import Image, ImageChops

image=Image.open('headbase1.png')
image.load()

imageSize = image.size
imageBox = image.getbbox()
print(image.getbbox())
cropped=image.crop(imageBox)
cropped.save('headbase_end.png')


It does not crop out the transparency around it, and the bounding box is this (0, 0, 45, 45), which I do not think is right.


Thanks, VOT.


Aucun commentaire:

Enregistrer un commentaire