Copy link to clipboard
Copied
Hi all, I 'm looking to hopefully find (preferred) or create (if needed) an action or script that will automatically determine what the longest side of an opened file is and then change the shorter side of the canvas to the same pixel dimension as the longest one was so the file ends up with a square aspect ratio. I want this to work regardless of the original pixel dimensions of the file, the action/script should not need that to make the file square. The reason I want it to work this way is because we have many images that are all over the map in size and I want them, at this point in time, to stay that way. I just need them to be square instead of portrait or landscape. Secondly any extra canvas that is created should be filled with white. Does this exist or is there a specific way to record the action? I have tried in vain to create one or find one and have exceeded my ability level. Thank you in advance for any insight!
Yes, an action can (mostly) do this, there's no need for a script unless you prefer one.
The original image is copied to a new layer and rotated 90 degrees and a reveal all step to expand the canvas. Then delete the rotated layer. There are other steps, but these are the key ones.
Various steps will depend on whether you only have flattened images, or layered images and whether you wish to flatten the result of layers or retain the layers.
EDIT: Original action modified and download link u
...
You're welcome. Please mark the appropriate reply or replies as a correct answer to resolve the status of the discussion.
Searching for keywords of square or 1:1 does take some time! Most topics would likely be using fit image and canvas size as the requirement would be to normalise files to specific pixel dimensions. Using the rotated layer trick is less common, however, it's required in this case as you need variable dimensions based off each individual image. Without the
...Copy link to clipboard
Copied
Yes, an action can (mostly) do this, there's no need for a script unless you prefer one.
The original image is copied to a new layer and rotated 90 degrees and a reveal all step to expand the canvas. Then delete the rotated layer. There are other steps, but these are the key ones.
Various steps will depend on whether you only have flattened images, or layered images and whether you wish to flatten the result of layers or retain the layers.
EDIT: Original action modified and download link updated!
Action download:
P.S. There are many topics in the forum for creating square 1:1 ratio images.
Copy link to clipboard
Copied
Thank you Stephen! This is super helpful and a solution I wouldn't have thought of. I did try to search for the topic but was not having great success with my search terms to find this type of answer. Thanks again!!
Copy link to clipboard
Copied
I propose 2 solutions
the first normal
var doc = app.activeDocument;
var docW = parseFloat(doc.width.as("px"));
var docH = parseFloat(doc.height.as("px"));
if (docW > docH){
doc.resizeCanvas(UnitValue(docW, "px"), UnitValue(docW, "px"));
}else{
doc.resizeCanvas(UnitValue(docH, "px"), UnitValue(docH, "px"));
}
The second solution allows you to resize the image
resizeARC(900);
function resizeARC(size){
var doc = app.activeDocument;
var docW = parseFloat(doc.width.as("px"));
var docH = parseFloat(doc.height.as("px"));
if (docW > docH){
doc.resizeCanvas(UnitValue(docW, "px"), UnitValue(docW, "px"));
doc.resizeImage(UnitValue(size, "px"));
}else{
doc.resizeCanvas(UnitValue(docH, "px"), UnitValue(docH, "px"));
doc.resizeImage(undefined, UnitValue(size, "px"),);
}
}
Please note that the background color is used as a color fill.
Copy link to clipboard
Copied
You're welcome. Please mark the appropriate reply or replies as a correct answer to resolve the status of the discussion.
Searching for keywords of square or 1:1 does take some time! Most topics would likely be using fit image and canvas size as the requirement would be to normalise files to specific pixel dimensions. Using the rotated layer trick is less common, however, it's required in this case as you need variable dimensions based off each individual image. Without the rotated layer trick you would likely need a script for performing such logic.
Copy link to clipboard
Copied
All set now, thanks again!
Copy link to clipboard
Copied
Hi
This is really interesting and what i was looking for, but i cant stop it from making a white background, even after i edit the action fill to black. Any help appreciated.
Copy link to clipboard
Copied
Hi
This is really interesting and what i was looking for, but i cant stop it from making a white background, even after i edit the action fill to black. Any help appreciated.
By @simonbrattphotography
Record your action like this:
1) If there's a Background layer, start by unlocking it to become a standard layer capable of accepting transparency.
2) Ctrl/Cmd + J to dupe the layer
3) Edit > Transform > Rotate the layer 90°
4) Image > Reveal All
5) Delete the rotated layer as it has served it's purpose
6) Add a new solid fill layer in black
7a) Change it's blend mode to Lighten
or
7b) Move it to the bottom of the layer stack using Ctrl/Cmd + Shift + [