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

Resize a layer

Enthusiast ,
Jan 07, 2025 Jan 07, 2025

I want to resize a layer to this size 6000x4000
But I didn't find anything in uxp
Does anyone have a piece of code I can use.

TOPICS
Actions and scripting
1.1K
Translate
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 , Jan 07, 2025 Jan 07, 2025

Layer bounds is still a thing in UXP, so I'd start there:

 

https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/bounds/

 

I'll take a look when I have some free time.

 

Converting the layer to a smart object and editing the content and using image size to a specific px target is also possible for batchPlay UXP, but has more overhead.

Translate
Adobe
Community Expert ,
Jan 07, 2025 Jan 07, 2025

Are you deliberately avoiding ESTK-code? 

Translate
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 07, 2025 Jan 07, 2025

If I can do it in uxp it's better
Alternatively I try with estk.

Translate
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 07, 2025 Jan 07, 2025

Layer bounds is still a thing in UXP, so I'd start there:

 

https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/bounds/

 

I'll take a look when I have some free time.

 

Converting the layer to a smart object and editing the content and using image size to a specific px target is also possible for batchPlay UXP, but has more overhead.

Translate
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 07, 2025 Jan 07, 2025

This BatchPlay code was generated with the help of AI (the generated DOM code was useless). Adjust the interpolationType as required:

 

const app = require('photoshop').app;
const batchPlay = require('photoshop').action.batchPlay;

resizeLayer();

async function resizeLayer() {
    const command = {
        _obj: "transform",
        width: {
            _unit: "pixelsUnit",
            _value: 6000
        },
        height: {
            _unit: "pixelsUnit",
            _value: 4000
        },
        linked: false,
        interfaceIconFrameDimmed: {
            _enum: "interpolationType",
            _value: "bilinear"
        },
    };

    try {
        await batchPlay([command], {});
        console.log("Resize completed!");
    } catch (err) {
        console.error(err);
    }
}

 

Translate
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 08, 2025 Jan 08, 2025

I used the convert to smart object method

Translate
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 08, 2025 Jan 08, 2025
quote

I used the convert to smart object method


By @Ciccillotto


Curious! Obviously performance and workflow aren't an issue.

 

  1. Convert to SO
  2. Edit the SO
  3. Image Size
  4. Close/Save the SO
  5. Optionally convert the SO back to a layer or rasterize
Translate
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 08, 2025 Jan 08, 2025

Stefano I used the convert to smart object method just because it was easier at the moment, The uxp code you put doesn't work and finding the problem would have cost me time, which I don't have at the moment. Maybe if I free myself up a bit I'll see if I can make it work.

Translate
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 08, 2025 Jan 08, 2025
quote

Stefano I used the convert to smart object method just because it was easier at the moment, The uxp code you put doesn't work and finding the problem would have cost me time, which I don't have at the moment. Maybe if I free myself up a bit I'll see if I can make it work.


By @Ciccillotto

 

Ah OK, the .psjs file obviously worked for me (Ps 2024).

Translate
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 08, 2025 Jan 08, 2025

I hadn't thought about psjs, I'll try it later, if it goes well I'll use this method. Thanks for your help.

Translate
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 09, 2025 Jan 09, 2025

Stefano I tried with psjs and it works fine
thanks a lot for your help

Translate
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 09, 2025 Jan 09, 2025
quote

Stefano I tried with psjs and it works fine
thanks a lot for your help


By @Ciccillotto


You're welcome! It always resizes from the default middle-centre. I couldn't work out how to change the resize anchor point.

Translate
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 09, 2025 Jan 09, 2025

I also had this problem
I solved it using center vertical level and center horizontal

kindly tell me with which AI you created the script above.

Translate
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 09, 2025 Jan 09, 2025
LATEST

Yes, post transformation alignment or X/Y translation.

 

As for AI, I tried "the big 3" - ChatGPT, Claude and CoPilot (surprisingly, Gemini is almost useless for Photoshop scripting).

 

I tried many iterations of UXP DOM code before giving up and asking it to use BatchPlay instead. 

I can't remember which of the 3 provided the final working code, or perhaps it was a combination - feeding the output of one as the input to another.

Translate
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