Copied from https://github.com/asystat/Final-Android-Resizer. Customed for own needs