bcrop Automatically crop borders from images. This code is really messy, but it works reasonably well.