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

How can I resize a layer (or text) to a percentage of the canvas?

Community Beginner ,
Sep 29, 2024 Sep 29, 2024

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.

TOPICS
Actions and scripting

Views

117

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

correct answers 1 Correct answer

Community Expert , Sep 29, 2024 Sep 29, 2024

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 = 
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 29, 2024 Sep 29, 2024

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

 

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 ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

LATEST

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:

  • Type text (that's the correct size for only one size of image - I want to make this step so it's percentage based off the size of the canvas)
  • Layer via copy (3 times, so there's 4 copies)
  • Select first layer
    • Select all
    • Align layer top left corner
    • Move in and down a specific amount (I guess this needs to be percentage-based too, but I think the action can handle that already by using percent instead of pixels)
  • Select second layer
    • Select all
    • Align  layer top right corner
    • Move in and down a specific amount
  • Etc... so there's one in each corner
  • Make them all a group
  • Add transparency channels of all 4 to layer mask

2024-09-30_18-06-59_Photoshop.png

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