Refactors imgmap tool. Moves all the important bits into
the imgmap.lib sub package, so it may be imported and used
in other tools.

Fixes the imgmap/lib api to return proper errors, instead of
writing directly to stderr.
Exports imgmap/lib.Apply function.