Function like "crop to content" from GIMP

please link to examples/specification of this thing in GIMP, and source code if possible.

please provide an example situation (code, data) on which you need this function performed, and how the result in GIMP looks like.