Skip to main content
Camst4
Inspiring
November 4, 2013
Answered

Script or Action - Make image square

  • November 4, 2013
  • 2 replies
  • 2803 views

Need to add this to an action, rather than making all images square manually before batching them all.

 

- All 500+ images are various sizes both portait, landscape and possibly square already.

- They are all cropped tightly around the product with a white background.

 

So currently: I just use canvas size, anchor to the centre and change the smallest pixel dimension to make it square, so none of the product is cropped.

 

Any ideas?

 

I couldn't get JJMack's aspect ratio script to help me.

Automate -> Fit Image will take it to 1000 pixels but still won't be square.

 

 

EDIT: Oh my. I just found this, looks like it'll do the job. Will test some more in the morning.

var savedRuler= app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var w = app.activeDocument.width;
var h = app.activeDocument.height;
if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
//if w==h already square
app.preferences.rulerUnits = savedRuler;

 

This topic has been closed for replies.
Correct answer Michael_L_Hale

Near the top where you set the ruler add these lines.

var startColor = app.backgroundColor;
if(startColor.rgb.hexValue != 'FFFFFF'){
	var white = new SolidColor();
	white.rgb.hexValue = 'FFFFFF';
	app.backgroundColor = white;
}

 

and at the bottom add this line

if(white != undefined) app.backgroundColor = startColor;

2 replies

OC graphic designer
Participating Frequently
November 4, 2021

I have the same problem, I have 1000's of product images with white backgrounds, both portrait and square. But as I scroll through the comment I feel out of my depth ... I'm a graphic designer, not a 'computer guy'. So, is there an action I can create or a droplet? I have been able to get to a point where I can do my landscpe images and portrait images by MANUALLY sorting them, but I cant Action/Droplet them all at once which would be a huge time saver.

 

It would be great if the Folks at Adobe would create an action that 'turns images into uniform size, square, 4:3 ... whatever!

 

HELP! 

JJMack
Community Expert
Community Expert
November 5, 2021

You need to crop your Images square then you can resize the square document canvas to canvas size you want.  The Plug-in script in my crafting Action Package AspectRatioSelection can be use in and actions to set  a centered square selection for you image document that you can Crop to.  Any Aspect Ration can be recorded into your Action. The Aspect ratio will be set for your the document being edited.  If you record  4 3  portrait will have a 3:4 Aspect Ratio selection set and landscape and square images will have a 4:3 Aspect Ratio selection set 

 

JJMack
Inspiring
November 4, 2013

! would add is a check of the background color and set it to white if needed.

Camst4
Camst4Author
Inspiring
November 5, 2013

Ahh yep ok. How do I do that?

Michael_L_HaleCorrect answer
Inspiring
November 5, 2013

Near the top where you set the ruler add these lines.

var startColor = app.backgroundColor;
if(startColor.rgb.hexValue != 'FFFFFF'){
	var white = new SolidColor();
	white.rgb.hexValue = 'FFFFFF';
	app.backgroundColor = white;
}

 

and at the bottom add this line

if(white != undefined) app.backgroundColor = startColor;