Hey,
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?
Hey,
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
You want to maintain an aspect ratio of y/x
, which means that you need to compute y/x
for the original image. Let z = y/x
, then, given any new height y'
(in your case, 60 px), to find the new width x'
:
y/x = z = y'/x'
x' = y' * z
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...