calculate best image size