I have a bunch of images that aren't equal size, and where some fit entirely to the frame and some have blank padding.
I would like to know how I can resize each of them to be the same image size and to have roughly the same border size.
Currently I am doing
from PIL import Image
from glob import glob
images = glob('src/assets/emotes/medals/**/*.png', recursive=True)
for image_path in images:
im = Image.open(image_path).convert('RGBA')
im = im.resize((100, 100))
im.save(image_path)
but this doesn't account for a possible border.
Images arent always bigger than (100, 100)
so I will need to use resize.
I can also maybe remove the PNG border for all images, and then resize which might be easier.
CodePudding user response:
Taken from Crop a PNG image to its minimum size, im.getbbox()
will give you the original image without transparent background.
Documentation : Pillow (PIL Fork)