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

Resize a layer

Engaged ,
Jan 07, 2025 Jan 07, 2025

Copy link to clipboard

Copied

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

Views

208

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

Votes

Translate

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

Copy link to clipboard

Copied

Are you deliberately avoiding ESTK-code? 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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);
    }
}

 

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

Copy link to clipboard

Copied

I used the convert to smart object method

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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