Image Resizing

Moderator: Kathy_9

Post Reply
tommyallitt
Posts: 2
Joined: Sat Oct 06, 2018 11:00 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit

Image Resizing

Post by tommyallitt »

Hi Guys,

Sorry if this has been asked before.

I need what I think is a basic script that I can use in batch processing that will open and image and make the smallest side the same as the longest side and then resize the entire image to 1000x1000 pixels unless it is less than 1000 pixels x 1000pixels already.

If someone could point me in the right direction I’d really appreciate it.

Many Thanks

Tom
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Image Resizing

Post by LeviFiction »

No, this particular thing has not been asked before, I don't believe. Most people are against distorting their images. I have been asked to make a script that adds a border to the short side to make it equal to the long side, no resizing necessary. It just ends up with a black box around it.

I think you could do this easily by recording a simple resize action into a script. Don't worry about the values, just record a script that uses resize and save it out. Open the script in an editor like notepad. Then adding a single line of code just before the Resize command, and finally replacing the appropriate parameters in the resize command with the variable we create.

Python has this neat function called "max" which takes two numbers and returns whichever number is greater. It also has the opposite called 'min' which returns the smaller of the two numbers. What we do is we pass in the width and height to max() and it tells us what the longest side is. Then we pass this into min() with the number 1000 and whichever is smaller becomes the new resize parameter we'll use. The code looks like this

Code: Select all

SideLength = min( max( App.TargetDocument.Width, App.TargetDocument.Height ), 1000 )

#resize command begins here
Then replace the Width and Height values in the Resize command with SideLength

Code: Select all

#This is pseudo code and cannot be run by PSP
App.Do( Environment, 'Resize', {
    #....other parameters,

    'Height': SideLength,
    'Width': SideLength,

    #....other parameters
    }
The end result is the image is distorted to make the width and height match, and if they are larger than 1000px they are resized down to 1000px. If they are smaller than 1000px then nothing else is done.
https://levifiction.wordpress.com/
tommyallitt
Posts: 2
Joined: Sat Oct 06, 2018 11:00 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit

Re: Image Resizing

Post by tommyallitt »

Hi Levi,

Thank you so much. That was a huge help. Just what I needed. I tweaked it slightly to give what I needed as I didn’t want to distort the images so I used the max function to set the canvas size and then used the min function to resize the image to 1000 unless it was already smaller than that.

This will save me a huge amount of time when preparing product images for our website.

Thanks again.

Tom
Post Reply