0

I'm trying to create an action that makes the width of the canvas equal to its height.

I tried using cut and paste and tabbing between them, but this only works on the first picture.

Any I try after, just resize to the height of the original recording.

please help

i must do 350 a week, various size images, needing to be a perfect square.

I was going to create 2 actions, one if the height was larger and one if the width was larger, i need the square to be based on the larger of width and height

thanks corey

1
  • Can you provide some more information about the source sizes and desired destination size? Are they consistent? It’s probably possible to do what you’re after with a single action. Apr 16, 2017 at 9:52

4 Answers 4

3

This might work for you, and this will work on both landscape and portrait images, cropping a 1.1 ratio square to your largest width or height.

If you record these steps below it will give you the result you need.

  1. Duplicate current layer
  2. Rotate current layer 90 degrees
  3. Reveal all
  4. Delete current layer

enter image description here

Then you can add a Save action if you need to save it, or load this action into File > Scripts > Image Processor for images in multiple locations.

Download the action here: Stack Exchange - Square Crop.atn

2

This was a really handy question for me, even though 3 years old...

The script example given is a little out of date for current CC versions, so I thought I'd update it here with my tweaked version.

This script will maximise square crop to the longest side, regardless what size the base image is - this was particularly useful when faced with 100s of tall portrait images I wanted to force square, without cropping any of the original image out.

I elected to not save the file from within the script, but used PS 'Save as...' in the action so that I could save PNG as JPG without the transparency, and force a white background so that cutouts and jpgs were all treated the same in the end.

Updated script:

// get current active document
doc = app.activeDocument; 

// create variables
var bounds, left, top, right, bottom;

// get the current height and width as a numeric value
// (otherwise you'll get '1000 px' as doc.<dimension>)
const height = doc.height.value;
const width = doc.width.value;

if(height > width) {
    // offset the left side
    left = 0 - (height - width)/2;
    top = 0;
    // and the right
    right = 0 + (width + height)/2;
    bottom = height;
} else {
    left = 0;
    // offset top
    top = 0 - (width - height)/2;
    right = width;
    // and bottom
    bottom = 0 + (height + width)/2;
}

bounds = [left, top, right, bottom];
doc.crop(bounds);

Who knew PS could be scripted so easily! Off exploring opportunities now...

Hope this helps someone else.

1

You can use Photoshop Scripting to do this.

Save the following into a new file called squarecrop.js in some folder that is convenient for you. You'll want to leave it there so you can use it in the future. This will find whether the image is wider or taller and crop accordingly, keeping the center of the image. It does not check to see if the image is already square, I assume you won't be doing anything to those images.

#target photoshop
// get current active document
doc = app.activeDocument; 

// create variables
var bounds, left, top, right, bottom;

if(doc.height > doc.width) {
    // document is taller, need to crop to square based on width
    left = 0;
    top = (doc.height-doc.width)/2;
    right = doc.width;
    bottom = top + doc.width;
} else {
    // document is wider, need to crop to square based on height
    left = (doc.width-doc.height)/2;
    top = 0;
    right = left + doc.height;
    bottom = doc.height;
}

// set bounds for cropping
bounds = [left, top, right, bottom];
doc.crop(bounds);

//~~~ SAVES OVER ORIGINAL FILE AND CLOSES ~~~
doc.close(SaveOptions.SAVECHANGES);
//alternately, you can use doc.save(); to save without closing.

Note that, as the comment at the end says, this will OVERWRITE the original of the file you run it on. Make sure you're planning for that to happen.

Next! Open up a file. Create a new action, call it whatever you want. Start recording. Go to File > Scripts > Browse and choose squarecrop.js wherever you put it. The document you have open should crop, save, and close automatically. Stop recording the action.

For more info, see the photoshop scripting documentation: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref-2015.pdf

0

Here is a photoshop action I made to automate the process.

I named it Square Crop by trim

  • Duplicate current layer
    Name: "Vert Mask Layer"
  • Set Selection
    To: All
  • Rotate current layer
    Angle 90
  • Hide background
  • Trim
    Based on: Transparent pixels
    With Trim Top
    With Trim Bottom
    With Trim Left
    With Trim Right
  • Show Background
  • Hide current layer
  • Delete current layer
  • Set Selection
    To: None

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.