VID-1810 Redo the janky image handling that existed before

@garthwebb I also notice that there are some similar calculations happening in the backend thumbnailer code [here](https://github.com/Wikia/backend/blob/master/lib/Wikia/Thumbnailer/Image.pm#L75-208). Are you familiar with how that works?