Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Image import sys image=Image.open('L_2d.png') image.load() imageSize = image.size imageBox = image.getbbox() imageComponents = image.split() rgbImage = Image.new("RGB", imageSize, (0,0,0)) rgbImage.paste(image, mask=imageComponents[3]) croppedBox = rgbImage.getbbox() print imageBox print croppedBox if imageBox != croppedBox: cropped=image.crop(croppedBox) print 'L_2d.png:', "Size:", imageSize, "New Size:",croppedBox cropped.save('L_2d_cropped.png')
- th
- Install Pillow
- pip install Pillow
- and use as
- from PIL import Image image=Image.open('L_2d.png') imageBox = image.getbbox() cropped = image.crop(imageBox) cropped.save('L_2d_cropped.png')
- for more:https://cuty.io/9Nq6cUDK6mO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement