Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
3

Action or script to automatically make image square regardless of original size or orientation

Community Beginner ,
Feb 19, 2024 Feb 19, 2024

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!

TOPICS
Actions and scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Feb 19, 2024 Feb 19, 2024

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

...
Translate
Community Expert , Feb 20, 2024 Feb 20, 2024

@alimedi77729338 

 

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

...
Translate
Adobe
Community Expert ,
Feb 19, 2024 Feb 19, 2024

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!

 

square_atn.png

 

Action download:

https://www.dropbox.com/scl/fi/15uyh98xpqce58x114gk9/Resize-to-Square-with-White-BG.atn?rlkey=6edi3k...

 

P.S. There are many topics in the forum for creating square 1:1 ratio images.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 20, 2024 Feb 20, 2024

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!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 20, 2024 Feb 20, 2024

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2024 Feb 20, 2024

@alimedi77729338 

 

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 21, 2024 Feb 21, 2024

All set now, thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 23, 2025 Mar 23, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2025 Mar 23, 2025
LATEST
quote

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 [

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines