updated code, and centered the image when smaller than full fit