So to make this algorithm general, you will need to know your target screen width, target screen height, and image width and height.
Code:
if (image height > screen height) then
use: (image width/image height) * (screen height / screen width) as % of width
else
use: 100% of width
Is that correct?