Resizing image with Python with locked aspect ratio

Posted by David Vinklar on Stack Overflow See other posts from Stack Overflow or by David Vinklar
Published on 2010-04-20T10:34:45Z Indexed on 2010/04/20 10:53 UTC
Read the original article Hit count: 331

Filed under:
|
|
|
|

How should I resize an image with Python script so that it would automatically adjust the Height ratio to the Width used? I'm using the following code:

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, 
            })

Using this code works perfectly if the aspect ratio of an image is the same as the one defined in the code - i.e. 1.33333. But how should I make it work with images that do not have this ratio? For me, what is important is that the new Width is 1920; Height has to be able to adjust automatically. Any ideas which part of my code should be altered and how?

© Stack Overflow or respective owner

Related posts about python

Related posts about resizing