Fix bug when handling non-square images.