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

resize layer 1 with the dimension of the background image

Community Beginner ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

i need to resize layer 1 to the same size as the background, automatically.

I tried with actions, but it doesn't work, how to make a script?sadaa.jpg 

TOPICS
Actions and scripting , Windows

Views

727

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 , Apr 06, 2020 Apr 06, 2020

Here is a simple script to distort the active layer to match the canvas. The layer to resize needs to be pre-selected/targeted in the layers panel before running the script. When recording the action you can use an absolute/explicit selection of "Layer 1" or you can use a relative keyboard shortcut to select the uppermost layer opt/alt . (dot/period character):

 

 

//community.adobe.com/t5/photoshop/scale-layer-to-current-canvas-size-photoshop/td-p/5217315
// Michael L Hale
function main() {
   
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

Hi, you need to record an action then it works for you first need to learn record to it... regards

Ali Sajjad / Graphic Design Trainer / Freelancer / Adobe Certified Professional

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 ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

thanks for responding, but as i said in the post. action does not work for this job

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 ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

You will need a script. Try searching for one on the forums.

 

What should the script do to match the layer size to the background/canvas size?

 

Should the script distort/stretch both the width and height to match?

 

Or should the script only size the width of the layer to match the canvas, potentially making the height proportionally larger or smaller than the width?

 

Or should the script only size the height of the layer to match the canvas, potentially making the width proportionally larger or smaller than the height?

 

Are all the images canvas that will be processed portrait orientation, or will some be landscape? Should the script intelligently scale to "best fit" for the orientation of portrait or landscape canvas? 

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 ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

Here is a simple script to distort the active layer to match the canvas. The layer to resize needs to be pre-selected/targeted in the layers panel before running the script. When recording the action you can use an absolute/explicit selection of "Layer 1" or you can use a relative keyboard shortcut to select the uppermost layer opt/alt . (dot/period character):

 

 

//community.adobe.com/t5/photoshop/scale-layer-to-current-canvas-size-photoshop/td-p/5217315
// Michael L Hale
function main() {
    var doc = app.activeDocument;
    var layer = doc.activeLayer;
    layer.translate(new UnitValue(0 - layer.bounds[0].as('px'), 'px'), new UnitValue(0 - layer.bounds[1].as('px'), 'px'));
    layer.resize((doc.width.value / (layer.bounds[2] - layer.bounds[0])) * 100, (doc.height.value / (layer.bounds[3] - layer.bounds[1])) * 100, AnchorPosition.TOPLEFT);
}
app.activeDocument.suspendHistory('Resize Layer to Canvas', 'main()');

 

 

EDIT: This variation will select the layer named "Layer 1":

 

function main() {
    var doc = app.activeDocument;
    doc.activeLayer = doc.layers.getByName("Layer 1");
    var layer = doc.activeLayer;
    layer.translate(new UnitValue(0 - layer.bounds[0].as('px'), 'px'), new UnitValue(0 - layer.bounds[1].as('px'), 'px'));
    layer.resize((doc.width.value / (layer.bounds[2] - layer.bounds[0])) * 100, (doc.height.value / (layer.bounds[3] - layer.bounds[1])) * 100, AnchorPosition.TOPLEFT);
}
app.activeDocument.suspendHistory('Resize Layer to Canvas', 'main()');

 

You can record the script into an action as a step.

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

EDIT: And here is another script that achieves the same result:

https://gist.githubusercontent.com/jawinn/ab4df1c33d0743e41fd3/raw/72ff297ae42ed029c86be7644bd021ef4...

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 ,
Apr 07, 2020 Apr 07, 2020

Copy link to clipboard

Copied

Thank you very much!!!

 

This script worked perfectly.

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 ,
Apr 07, 2020 Apr 07, 2020

Copy link to clipboard

Copied

Glad to be of help and thank you for updating the topic with a correct answer to help others in the future (not everybody has the courtesy to come back, say thank you and or give feedback, press like or mark correct).

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
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

This code is great for layering images
But I want to use this code on a paragraph text or a text layer, but I find that the text has changed the font .. Is it possible to match the font size with the dimensions of the design

 

These images show a text layer and its dimensions outside the design

00003.jpg

When executing the code, the dimensions of the text are adapted to the dimensions of the design, but the font size changes
I want a code that matches the font size with the dimensions of the text layer and the dimensions of the design

004.jpg

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 ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

If it wasn't obvious, the hack to that script was never intended to be used on text layers. I'll give it a look, working with text frames and content in Photoshop can be challenging.

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 ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

For a scripted solution, I believe that this would require advanced scripting knowledge of Action Manager code, which is beyond my current experience or abilities.

 

Easy to do manually though, with the text tool active, double click the text layer icon or click on the layer on the canvas to insert the i-beam insertion point into the text layer so that the content is active for editing, then manually resize the frame/bounding box to the document edges and confirm the change of the bounding box without actually changing any of the actual text content.

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
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

The code you made works really well
But it only requires scaling the font size to fit the document size

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 ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

The text content is affected by the text bouding box modification.

 

In order to adjust the bounding box separately from the content, one must enter the modal text editing mode and then manually adjust the bounding box while in the modal edit (which prohibits scripting while in the modal edit).

 

As I said in my first post:

 

"If it wasn't obvious, the hack to that script was never intended to be used on text layers."

 

"working with text frames and content in Photoshop can be challenging"

 

"For a scripted solution, I believe that this would require advanced scripting knowledge of Action Manager code, which is beyond my current experience or abilities."

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
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

Thank you for your interest

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 ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

LATEST

Try searching for the forum with keywords similar to "script resize text box" or variations of. One such hit:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/any-way-to-reset-text-box-scale-after...

 

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