Calculated the image size and position real-time. Now the image is correctly centered and scaled.