Answer the question
In order to leave comments, you need to log in
How to automate canvas size rounding in Photoshop?
In my line of work, I often have to process heaps of files, performing heaps of operations, all of which are beautifully templated. Except for one - rounding the size of the type 5000.5x1500.5mm down .
For this I wrote a simple script:
app.preferences.rulerUnits = Units.MM;
app.activeDocument.resizeCanvas (Math.floor(app.activeDocument.width), Math.floor(app.activeDocument.height), AnchorPosition.TOPLEFT);
Math.floor(app.activeDocument.width.toFixed(2))
Answer the question
In order to leave comments, you need to log in
It's not about knowing JS, but about understanding what is happening.
The size must be calculated in advance and checked, I believe, whether it is divisible by 2 without a remainder. If it is divisible, then nothing needs to be changed;
Before app.activeDocument.resizeCanvas, you need to add an if statement in which to check whether rounding is necessary. In the app.activeDocument.resizeCanvas method itself, you need to substitute variables containing the rounding/non-rounding result that passed the if test, and not calculate the result on the spot.
app.preferences.rulerUnits = Units.MM;
width = app.activeDocument.width;
height = app.activeDocument.height;
// Не знаю синтаксис, пишу по наитию, но должно выглядеть как-то так
if(width % 2) width = Math.floor(width);
if(height % 2) height = Math.floor(height);
app.activeDocument.resizeCanvas (width, height, AnchorPosition.TOPLEFT);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question