Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Create script to use canvas size to square the image by the largest dimension.

New Here ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

I would like to square images.  The images have various rectangular dimensions.  I would like each image to be canvased by the largest dimension then automate the process for each photo and it's largest dimensions.

automated example

7000 X 3005  to  7000 x 70000

5454 x 2500  to  5454 x 5454

Views

837

Likes

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 1 Correct answer

Adobe Community Professional , Oct 16, 2018 Oct 16, 2018
A forum search kicked this one up (thank you Chuck Uebele). The script creates a white background on flattened images and transparency on layered images:https://forums.adobe.com/message/6424562#6424562I have added a couple of lines of code to save/restore the original ruler units.//https://forums.adobe.com/message/6424562#6424562//https://forums.adobe.com/message/10683707#10683707#target photoshopvar savedRuler = app.preferences.rulerUnits; //save the current ruler unitsapp.preferences.rulerUnit...

Likes

Translate

Translate
Adobe Community Professional ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

If all the files are flat image file without transparency a relatively easy Photoshop script you can write could do the deed.  Processing 40,000 image files will take a long time. If the files may be layered image file that may transparency adding canvas may add transparent canvas boarders and tthe image will not look like a 1:1 aspect ratio  square image, Using such an image in a composite using Photoshop tools may trim off transparent borders. 

I believe an action can not do the deed for an Action can not use logic to examine side sizes and use  logic to add the right amount of canvas to the  right side of the image..

If you nee help writing the script there is a Photoshop scripting forum Photoshop Scripting

JJMack

Likes

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
New Here ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Thanks  I was hoping for some automation of the process to square each image by its largest dimension .

Likes

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
Adobe Community Professional ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

After you write it it will be.

JJMack

Likes

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
New Here ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

I don't see how it will do it.  can u give a mini step by step please

Likes

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
Adobe Community Professional ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

The logics is strait forward. The script logic would go like this.  You would record using the script in an Action the patch that action.

save current units

set units to pixels

If active document width not equal active document height {

   if active document width is greater than active document height canvas size active document width, active document width; 

   else canvas size active document height, active document height;

   active document save

}

restore saved units

Image that were are not square would be made square and saved.

JJMack

Likes

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
Contributor ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

take a look at IrfanView. i think it can do what you want.

Likes

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
New Here ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

Sorry for the delay  i left work.   I  see thank you ...   I'm new to adobe  So  I have to download Adobe script and then run this script.   I see.

Thank You

Likes

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
Adobe Community Professional ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

No Adobe ScriptingSupport was an optional plug-in download for Photoshop Version 7.  It was incorporated into Photoshop in Photoshop CS and is in all version of Photoshop since  Photoshop CS.  If you look at your Menu Help>System info you should see that it is loaded.  Adobe uses Photoshop scripting for many things. Like Image Processor, load files into a stack, export layer to files.  You just need to write a script or use the one posted here.  The one posted here does not save any document. It would need to be recorded in an action and batched with menu File>Automate>Batch and have batch save document into a destination.  Or use menu File>Scripts>Image Processor it you want all Image file saved as a PSD or Jpeg or Tiff or all three types.   If you want a different File type saved you can download the Plug-In Image Processor Pro... and use menu File>Automate>Image Processor Pro to batch your action

40,0000 is a lot of files I can not think  of any reason someone would need 40,000 square Image files with different sizes some of which would have borders on top and bottom other with borders on left and right  where some border will be transparent  and others will be colored and some image file may have no boarders

JJMack

Likes

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
Adobe Community Professional ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

A forum search kicked this one up (thank you Chuck Uebele). The script creates a white background on flattened images and transparency on layered images:

https://forums.adobe.com/message/6424562#6424562

I have added a couple of lines of code to save/restore the original ruler units.

//https://forums.adobe.com/message/6424562#6424562

//https://forums.adobe.com/message/10683707#10683707

#target photoshop

var savedRuler = app.preferences.rulerUnits; //save the current ruler units

app.preferences.rulerUnits = Units.PIXELS;

var backgroundC = new SolidColor();

    backgroundC.rgb.red = 255;

    backgroundC.rgb.green = 255;

    backgroundC.rgb.blue = 255;

    backgroundColor = backgroundC;

  

var doc = activeDocument

doc.resizeCanvas(Math.max(doc.width,doc.height),Math.max(doc.width,doc.height))

//doc.resizeImage(1020,1020) //Uncomment to fit to a 1020px square rather than longest edge

app.preferences.rulerUnits = savedRuler; //restore the original ruler units

Prepression: Downloading and Installing Adobe Scripts

The script can be recorded into an Action and used with the Batch command or with Image Processor or Image Processor Pro for bulk processing. Test on a small number of images before attempting to process 40K!

Likes

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
New Here ,
Oct 24, 2021 Oct 24, 2021

Copy link to clipboard

Copied

LATEST

Just found your post and it was exactly what I needed! Thank you.

Likes

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