Image aspect ratio is maintained while fitting to canvas

This makes images maintain aspect ratio when fitted to canvas.

A lot of changes due to emacs removing trailing spaces sorry