Search code examples
mathscalingimage-scaling

Scaling images to an area


I'm trying to scale a bunch of images so that they have the same area, but keep their aspect ratio, but am having trouble find a formula to do so.

Does anyone know a formula?


Solution

  • For a given area A,

    newx * newy = A
    newx / newy = oldx / oldy
    

    which gives you:

    newy = A / newx
    newy = newx / (oldx / oldy)
    
    A / newx = newx / (oldx / oldy)
    A * oldx / oldy = newx ^ 2
    

    which then solves to:

    newx = sqrt(A * oldx / oldy)
    newy = A / newx
    

    Then again, this is a maths question, not a programming one...