Image 调整图像大小并保持纵横比

Image 调整图像大小并保持纵横比,image,aspect-ratio,Image,Aspect Ratio,给定高度和宽度。如何调整图像大小,使其包含在该图像的最大保持架中,同时保持纵横比?如下所示: 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

给定高度和宽度。如何调整图像大小,使其包含在该图像的最大保持架中,同时保持纵横比?

如下所示:

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
像这样:

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
运用你的数学知识

这会有帮助的

使用你的数学

这会有帮助的