Rick Lancee Rick Lancee - 1 year ago 105
Javascript Question

Figure out required height of an image, according to the dimension of a box inside that image

Title gore sorry, it's hard to describe.

I got an image, which is let's say,

in height. On that image i know the dimensions and position of a box, which is
tall. The box inside scales proportionally to the height of the image. I need to figure out which height i need to set the image to in order to get the height of the box to match
. I can only set the height of the image.

Known variables

boxHeight = 800
imageHeight = 1000
desiredBoxHeight = 600
requiredImageHeight = ??

Here what i mean: Left, the current situation, right the desired situation.
Whats the math in order to figure out the height of the image in the right situation?

I've tried and tried, but i'm not a math person, so i'm at wit's end.

Answer Source

If I understand correctly; The image scales proportionally to the size of the box. The box goes from 800 to 600 pixels. So the image goes from 1000 to 1000 * (600/800) = 750 pixels.

So that's:

requiredImageHeight  = imageHeight * (desiredBoxHeight / boxHeight)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download