Search code examples
canvasautomationphotoshopimage-resizing

Resize batch images in PhotoShop


I am frequently presented with the task of resizing images (lots of them) to a square and then saving them with PhotoShop. For example, if an image is 400x200 then I would need to resize the canvas to be 400x400. Likewise, if an image is 321x850 then the canvas would be resized to 850x850 if, and if the image is 521x250 then the canvas would be resized to 521x521.

Is there a way in PhotoShop to automate this tedious task? I know about PhotoShop automate, which records your actions, but that's not what I want. I have no problem programming the solution if you could point me in the right direction. Is this possible?

Thank you in advance. This could save me hours and hours of tedious repetitive work.


Solution

  • Using javascript: You can use this answer to pick all the files in a chosen folder and loop through them. Within the loop you'll want to open each file like so:

    var doc = open(fileList[i]);
    

    then do a check of the length vs width:

    if (doc.width !== doc.height) {             // if document is not already square...
        if (doc.width > doc.height) {               // if width is greater...
            doc.resizeCanvas(doc.width, doc.width)   // use this value for both sides...
        } else {                                      // else use height for both sides...
            doc.resizeCanvas(doc.height, doc.height)      // so you always get a square.
        }
    }
    

    save and close:

    doc.save();
    doc.close();
    

    Depending on what you're looking for there is doc.resizeImage() as well.

    Adobe scripting guides