2

I have a series of small images, all on white backgrounds.

Some of them are square proportioned, others are rectangular proportioned; either vertically or horizontally. I'm looking to make all all of the images square, the size doesn't matter but the proportion does.

Is there a quick way to batch process all images so that it turns rectangular images into squared images while keeping them centered and also ignoring images that are already square?

I'd try a macro or script, but I don't know how to code something like: "make the image and bigger at its biggest side".

I'm working with Photoshop but I can upload the images to any online tool if needed.

4
  • Is there any reason why you couldn't separate the images first? If you can do that you can just use the built-in Batch-Processing feature in Photoshop. Dec 12, 2017 at 22:26
  • @Ovaryraptor I could but will take some time, supposing I could quickly sort squared from non-squared images, how do I use the processor to make a rectangular image squared?
    – S. W. G.
    Dec 12, 2017 at 22:32
  • Please see my other answer. graphicdesign.stackexchange.com/a/97205/43400 Dec 12, 2017 at 22:35
  • If one of requirements is "while keeping them centered" then I'm afraid automation won't work. If the images were all in the same position it would work. Photoshop knows nothing about objects in a photo - there is no way for the software to automatically find where an object is.
    – Billy Kerr
    Dec 13, 2017 at 10:18

1 Answer 1

7

I won't go into detail about the batch process. It should be enough to know that you can run a script through the File > Automate > Batch... by first making a Photoshop Action, where you open a script file: File > Scripts > Browse.... Obviously you can also do more things within that same Action.

I'm not exactly confident I understand what you want, so I'm posting 2 scripts. Make a new .jsx file where you paste one of these scripts and use that in the action.

These both work with portrait and landscape images.

Image to square - Shrink script.jsx:

enter image description here

var rUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var doc = app.activeDocument;
var docWidth = doc.width;
var docHeight = doc.height;
var newSize = docWidth > docHeight ? docHeight : docWidth;

app.activeDocument.resizeCanvas( newSize, newSize, AnchorPosition.MIDDLECENTER );

app.preferences.rulerUnits = rUnits;

Image to square - Grow script.jsx:

enter image description here

The extended background color comes from the background color set in the toolbar.

var rUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var doc = app.activeDocument;
var docWidth = doc.width;
var docHeight = doc.height;
var newSize = docWidth > docHeight ? docWidth : docHeight;

app.activeDocument.resizeCanvas( newSize, newSize, AnchorPosition.MIDDLECENTER );

app.preferences.rulerUnits = rUnits;
12
  • amazing, right what I was looking for (2nd script) with the only difference that our images are always on white background, so If I set white in the toolbar I can run the batch with no issue right?
    – S. W. G.
    Dec 13, 2017 at 21:38
  • @S.Redrum, yes. You can test the script on a single image first.
    – Joonas
    Dec 13, 2017 at 21:44
  • it works like a charm, only stop I encountered was on one image where it asked to confirm the quality ratio for saving it. Can I add something to tell the script to also save the image with no prompt?
    – S. W. G.
    Dec 13, 2017 at 21:53
  • @S.Redrum uh oh... Should be possible, but I don't have an answer to that right now. I should've tested this on multiple images, but didn't. Gonna check that out....
    – Joonas
    Dec 13, 2017 at 22:28
  • @S.Redrum, oh wait. Now that I really read what you said, I realize that it wasn't the script that caused this dialog. The thing I don't quite get is why. Here's an example of how these things can happen. It's typically inconsistencies, like for example: If you make an action where you close a document and this document you use to make the action has been saved, it will close without ever showing you a dialog. Then... one of the images you run the action on has not been saved after changes. So when your Action tries to close it, it asks if you want to save the document or not,
    – Joonas
    Dec 14, 2017 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.