cropping and rotating layers when necessary. fixes #183