Merged code from stojg/slycrop.
See https://github.com/stojg/slycrop/pull/1 for more details