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

Action: Canvas Size as a calculation?

Community Beginner ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

I'm building an Action for series of operations I do at work all the time.

We get zillions of images, and I need to automatically make them 3:4 aspect ratio.

Here's what I need:

IF width > height

  • CANVAS SIZE
  • Height: [width x1.3333333]
  • Vertical: bottom
  • Extension Color: background color

IF width < height

  • CANVAS SIZE
  • Width: [height x0.75]
  • Horizontal: center
  • Extension Color: background color

There are other steps in the action I'm building, but I know how to do them. I even know how to do the "If-Then" part, using Insert Conditional in the Actions panel. I just don't know how to do the "Height = Width x 1.333333" and "Width = Height x 0.75" steps.

Any ideas?

Thanks!

Views

2.3K

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 Expert ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Photoshop Scripting can use logic like that. Actions only have conditional steps  you can insert into action and there are very few conditions you can test for. While you can test orientation like landscape and square.  And in this case you can change Canvas size a relative percentage of width and height in actions.  If the percentage is less that 100% you will be cropping your Image.  So with  conditional action steps and several actions you may be able to do what you want to do this time.   However if you really want to user logic automating Photoshop you need to learn how to script Photoshop.   The Process would be contains in a single file.  Conditional actions must be in the same Action set  but several actions are required to be recorded before you can insert  conditional steps.  You should look into Scripting Photoshop.

Your 75% Height  would crop  your Image. If you want to get the actual height and width values and use these in a calculation Scripting is required.

JJMack

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 ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Ah. I thought it might be something like that. Thank you, JJMack​, for your quick and clear answer.

Regrettably, I know nothing at all about how to do Photoshop scripts. But I'll sniff around, maybe I can figure it out.

Cheers!

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 ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Hi Greboguru,

You might ask in the Photoshop Scripting forum: Photoshop Scripting, or we can move this post if you want us to.

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 ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Regrettably, they know nothing at all about Photoshop scripting.  Most Photoshop Users will only use Photoshop scripts the will never write one.  Photoshop Ships with scripts like PhotoMerge,  Load files into a stack. lens correction, Export Layers to files. Image processor, contact sheet II and others.  There are also downloadable script on the web like Image Processor Pro.  So most Photoshop user use scripts but they are not programmers so they will never code a script.

JJMack

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 ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

A scripted solution would be something like this:

Re: fit canvas to specific ratio

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

#target photoshop

main ();

function main ()

{

  if (app.documents.length < 1)

  {

  alert ("No document open to resize.");

  return;

  }

  // These can be changed to create images with different aspect ratios.

  var arHeight = 3;

  var arWidth = 4;

  // Apply the resize to Photoshop's active (selected) document.

  var doc = app.activeDocument;

  // Get the image size in pixels.

  var pixelWidth = new UnitValue (doc.width, doc.width.type);

  var pixelHeight = new UnitValue (doc.height, doc.height.type);

  pixelWidth.convert ('px');

  pixelHeight.convert ('px');

  // Determine the target aspect ratio and the current aspect ratio of the image.

  var targetAr = arWidth / arHeight;

  var sourceAr = pixelWidth / pixelHeight;

  // Start by setting the current dimensions.

  var resizedWidth = pixelWidth;

  var resizedHeight = pixelHeight;

  // The source image aspect ratio determines which dimension, if any, needs to be changed.

  if (sourceAr < targetAr)

  resizedWidth = (arWidth * pixelHeight) / arHeight;

  else

  resizedHeight = (arHeight * pixelWidth) / arWidth;

  // Apply the change to the image.

  doc.resizeCanvas (resizedWidth, resizedHeight, AnchorPosition.MIDDLECENTER);

}

Prepression: Downloading and Installing Adobe Scripts

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 ,
Mar 22, 2019 Mar 22, 2019

Copy link to clipboard

Copied

Woah, thank you for this!!

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
New Here ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

LATEST

If anyone else is crawling the dead internet and has this same problem — here's a solution I was able to implement with actions instead of scripts. I used this method while processing a bunch of studio shots from random aspect ratios to all squares, but you could adapt it to different aspect ratios I think.

 

  • unlock background layer
  • extend canvas size to something much larger than you need
  • duplicate baground layer
  • rotate duplicate layer 90 degrees (you could then transform it by a % if you're looking for a different aspect ratio than a square)
  • Trim transparent pixels
  • delete duplicate layer

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