Copy link to clipboard
Copied
Using actions (or methods that can be recorded as actions):
How can I resize a layer (or text) to a known percentage of the canvas?
If I can get a layer to be any specific percentage of the canvas (i.e. 100% width of the canvas) then I can use the percentage sizing in transforms to get it to any size I want, all relative to the canvas size (I can easily align it left and transform it to width 20% for example). The problem is I can't figure out any way to get a starting point that's a known size relative to the canvas.
There might be a creative way with an action, but a script is what first comes to mind. Scripts can be recorded into an action as a step.
Try the following for just the document width:
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
docWidthScaler();
app.activeDocument.resolution = originalRulerUnits;
function docWidthScaler() {
var theLayer = app.activeDocument.activeLayer;
app.activeDocument.activeLayer = theLayer;
var scale =
...
Copy link to clipboard
Copied
There might be a creative way with an action, but a script is what first comes to mind. Scripts can be recorded into an action as a step.
Try the following for just the document width:
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
docWidthScaler();
app.activeDocument.resolution = originalRulerUnits;
function docWidthScaler() {
var theLayer = app.activeDocument.activeLayer;
app.activeDocument.activeLayer = theLayer;
var scale = Math.min(app.activeDocument.width / (theLayer.bounds[2] - theLayer.bounds[0]),
app.activeDocument.width / (theLayer.bounds[3] - theLayer.bounds[1]));
// Scale to N% of canvas
theLayer.resize(scale * 50, scale * 50);
// Centre on canvas
theLayer.translate(app.activeDocument.width / 2 - (theLayer.bounds[0] + theLayer.bounds[2]) / 2,
app.activeDocument.height / 2 - (theLayer.bounds[1] + theLayer.bounds[3]) / 2);
}
Or conditionally based on Portrait or Landscape document orientation:
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// Conditional resize layer by portrait or landscape orientation
if (app.activeDocument.height > app.activeDocument.width) {
scaleP();
} else {
scaleL();
}
app.activeDocument.resolution = originalRulerUnits;
function scaleP() {
var theLayer = app.activeDocument.activeLayer;
app.activeDocument.activeLayer = theLayer;
var scale = Math.min(app.activeDocument.width / (theLayer.bounds[2] - theLayer.bounds[0]),
app.activeDocument.width / (theLayer.bounds[3] - theLayer.bounds[1]));
// Scale to N% of canvas
theLayer.resize(scale * 50, scale * 50);
// Centre on canvas
theLayer.translate(app.activeDocument.width / 2 - (theLayer.bounds[0] + theLayer.bounds[2]) / 2,
app.activeDocument.height / 2 - (theLayer.bounds[1] + theLayer.bounds[3]) / 2);
}
function scaleL() {
var theLayer = app.activeDocument.activeLayer;
app.activeDocument.activeLayer = theLayer;
var scale = Math.min(app.activeDocument.width / (theLayer.bounds[2] - theLayer.bounds[0]),
app.activeDocument.height / (theLayer.bounds[3] - theLayer.bounds[1]));
// Scale to N% of canvas
theLayer.resize(scale * 50, scale * 50);
// Centre the text layer on canvas
theLayer.translate(app.activeDocument.width / 2 - (theLayer.bounds[0] + theLayer.bounds[2]) / 2,
app.activeDocument.height / 2 - (theLayer.bounds[1] + theLayer.bounds[3]) / 2);
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
Thanks, I guess I should just script it all. I was hoping there was some clever way to do it (because I'm lazy and have already got the actions, just trying to make them work on other-sized images as well)
At the moment my action is basically: