Use math and logics. You get the relative size by Width/Height. For example 400x200 would give you 2, also that 200x200 image would result 1. So if x>1, then image is horizontally bigger. Same relation number can be used as a multiplier.
For example if you draw image horizontally, you can
image.width := 50;
image.height := 50 / x;