tags:

views:

56

answers:

3

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?

+5  A: 

I think you are trying to maintain aspect ratio. If so use the following:

ratio = orginialHeight / newHeight

newWidth = orginialWidth * ratio

a432511
+1  A: 

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
Matt Ball
+2  A: 

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...

unwind
Given I'm not 100% sure I understand the intent of the question, but I think the OP wants to ADD 60 px to the original height, not multiply it by 60. Also, I've nearly always heard/used the term as "aspect ratio", not just "aspect".
PTBNL
@PTBNL: My solution doesn't add, it sets the height to 60.
unwind
@unwind: Sorry, I mis-read your answer the first time; indeed you do set the height to 60.
PTBNL