foTest
foTest

Reputation: 13

Resize Image and Maintain Aspect Ratio

Given a height and width. how can i resize the image to contain into my maximum holder for that image but maintaining aspect ratio?

Upvotes: 0

Views: 353

Answers (2)

elL
elL

Reputation: 777

use your mathmatics

this will help

enter image description here

Upvotes: 3

carlosdc
carlosdc

Reputation: 12142

Like this:

sx = original_width/destination_width
sy = original_height/destination_height
if sx*original_height > destination_height:
    s = sy
else:
    s = sx
new_width = original_width*s
new_height = original_height*s

Upvotes: 2

Related Questions