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

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

Community Beginner ,
Feb 19, 2024 Feb 19, 2024

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!

TOPICS
Actions and scripting

Views

184

Translate

Translate

Report

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

...

Votes

Translate

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

...

Votes

Translate

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

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!

 

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.

 

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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
Engaged ,
Feb 20, 2024 Feb 20, 2024

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.

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

@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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

All set now, thanks again!

Votes

Translate

Translate

Report

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