.comment-link {margin-left:.6em;}

Monday, December 26, 2005

 

Request For Comment

I've been pondering on a method of scaling down video under a certain number of overall pixels while maintaining aspect ratio. I came up with this:

width = sqrt(pixels * aspect)
height = sqrt(pixels / aspect)

So far that seems to work rather nicely. Is this correct, or is there a better way?

Comments:
pixels = width * height
aspect = width / height

width = sqrt(pixels * aspect)
= sqrt((width * height) * (width / height))
= sqrt(witdth * width * height / height)
= sqrt(width^2)
= width

height = sqrt(pixels / aspect)
= sqrt((width * height) / (width / height))
= sqrt(height^2)
= height

So your equations are certainly true. And if you have both the number of pixels and the aspect ratio handy, and don't mind doing a square root, then it doesn't seem too bad. I can't claim for certain that there's no better way though.

Peter McCurdy.
 
Post a Comment

Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?