PIL's getbbox is working for me
im.getbbox() => 4-tuple or None
Calculates the bounding box of the
non-zero regions in the image. The
bounding box is returned as a 4-tuple
defining the left, upper, right, and
lower pixel coordinate. If the image
is completely empty, this method
returns None.
Code Sample that I tried, I have tested with bmp, but it should work for png too.
import Image
im = Image.open("test.bmp")
im.size # (364, 471)
im.getbbox() # (64, 89, 278, 267)
im2 = im.crop(im.getbbox())
im2.size # (214, 178)
im2.save("test2.bmp")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…