views:

170

answers:

1

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?

A: 
balpha
Doesn't work. This is my PSP9 script. When I run it it still enforces 1440. Looks a bit trickier...
David Vinklar
@David Vinklar: Have you tried setting `AspectRatio` to `None` as well? After all, if given `AspectRatio = 1.3333` and `Width = 1920`, it makes sense that you still get 1440.
balpha
Yes!!! This is it! Now it works as wanted! Many thanks for your help!!!
David Vinklar
Then, accept the answer :-)
Roberto Liffredo
Done with pleasure...:-)Perhaps, one more small question. What is the meaning of the above value: 'Resolution': 72. If it was set to some other value, would that change something and if yes, what? Is it necessary to have it at all?
David Vinklar
>> Please edit this question to indicate what environment and image processor you are using.== As mentioned above, it is Paint Shop Pro 9 (PSP9) and WinXP SP3.
David Vinklar
Anybody knowing what is the meaning of the above value: 'Resolution': 72 ? What changes in the quality of the resize when this value is changed up or down?
David Vinklar
@David Vinklar: That's the DPI (because the units is set to `PixelsPerIn`); i.e. if you would change your desired width from 1920 pixels to 10 inches, the resulting width would be 720 pixels.
balpha
OK, but what practical implication on the quality of the resize has it? What would happen if I change it to, e.g. 125? Or if I just delete this line?
David Vinklar
@David Vinklar: Unless the image is going to be printed, there's no difference. You'll get the same result when you set the resolution to 300dpi and width to 2 inches as you'll get when you set the resolution to anything and width to 600px. Unless you want to say something like "I want this image to be printed at 450dpi at a width of 7.2cm", you can pretty much ignore the resolution parameter.
balpha
That's it! Thanks a lot!!
David Vinklar