使用Python和锁定纵横比调整图像大小

2024-09-28 23:51:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我应该如何使用Python脚本调整图像的大小,以便它能够根据使用的宽度自动调整高度比?我正在使用以下代码:

def Do(Environment):
    # Resize
    App.Do( Environment, 'Resize', {
            'AspectRatio': 1.33333, 
            'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
            'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
            'Height': 1440, 
            'MaintainAspectRatio': True, 
            'Resample': True, 
            'ResampleType': App.Constants.ResampleType.SmartSize, 
            'ResizeAllLayers': True, 
            'Resolution': 72, 
            'Width': 1920, 
            })

如果图像的纵横比与代码中定义的宽高比相同,即1.33333,则使用此代码非常有效。但是我该如何处理没有这个比例的图像呢?对我来说,重要的是新的宽度是1920;高度必须能够自动调整。有什么想法我的代码的哪一部分应该修改,如何修改?在


Tags: 代码图像脚本trueapp宽度高度environment