Recently we got a client with a special problem. A scanned paper with a signature has a lot of unused space around. The scan shows a bit of dust and dirt. People have greasy fingers, the flatbed scanner is not clean and the paper not perfect white. We have to clean it up and got a problem: The normal trim method in GMImageMBS class would remove some of the space, but a dust piece on the scan may prevent it from removing a bigger part.
We found a relative easy fix. We scale down the image to a much smaller size and all the dust points disappear. Now we can check for bounding box of the content and apply the found rectangle to the original picture.
Here is a simple code to show this:
Please try this. Trim and BoundingBox basically looks on the color in the edges and how far it reaches into the image. This way it can remove the whitespace. Don't forget to set colorfuzz to make sure it doesn't look for exact white, but allows some grayish pixels.