Adding support for non-square images

Makes both width and height parameters optional.

Also refactoring some of the image processing into another class.