I have an Image with the Value X width and Y height.
Now I want to set the height ever to 60px.
With which calculation I can calculate the height that the image is correct resized?
I think you are trying to maintain aspect ratio. If so use the following:
ratio = orginialHeight / newHeight
newWidth = orginialWidth * ratio
I assume you want the width after the rescale to relate to the height in the same way it did before the rescale, i.e. you want the aspect ratio to remain constant.
aspect_ratio = width_old / height_old
This gives:
aspect_ratio = width_new / height_new
Thus
width_new = width_old * height_new / height_old
Which means
width_new = (60 * width_old) / height_old
For instance, assume an incoming image of 640x480 (plain old VGA). This has an aspect_ratio
of 1.33333...
Rescaling this to be 60 pixels high would then require a new width of 60 * 640 / 480, or 80, which seems proper since 80/60 is indeed 1.3333...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With