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
IF width < height
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!
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.
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!
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.
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.
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);
}
Copy link to clipboard
Copied
Woah, thank you for this!!
Copy link to clipboard
Copied
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.