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

Is there a way to resize the document but keep the aspect ratio of the content?

Engaged ,
Jan 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

With scripting there is currentDocument.resizeImage() and currentDocument.resizeCanvas(). The resizeImage() method will stretch the image. The resizeCanvas() will resize the canvas but not change the size of the image.

I'm looking to resize the canvas to a new size but keep the aspect ratio of the content. Is there a way to do this?

TOPICS
Actions and scripting

Views

483

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

Engaged , Jan 20, 2016 Jan 20, 2016

OK I got it working!

                        adjustedWidth = width;

                        adjustedHeight = height;

                      

                        if (imageAspectRatio > targetAspectRatio) {

                            adjustedHeight = width / imageAspectRatio;

                        }

                        else {

                            adjustedWidth = height * imageAspectRatio;

                        }

                      

                        currentDocument.resizeImage(a

...

Votes

Translate

Translate
Adobe
Adobe Employee ,
Jan 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

Hi,

The ratio can be maintained when you resize the image but not the canvas.

img-size.PNG

Regards,

Chetna

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 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

Hi Chetna,

Thanks. The scripting engine does not appear to have that option. Here are the options in the Photoshop CS5 JavaScript Ref:

Screen Shot 2016-01-20 at 4.02.17 PM.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
Adobe Employee ,
Jan 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

Moving the thread to Photoshop Scripting for further assistance.

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 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

LATEST

OK I got it working!

                        adjustedWidth = width;

                        adjustedHeight = height;

                      

                        if (imageAspectRatio > targetAspectRatio) {

                            adjustedHeight = width / imageAspectRatio;

                        }

                        else {

                            adjustedWidth = height * imageAspectRatio;

                        }

                      

                        currentDocument.resizeImage(adjustedWidth, adjustedHeight, null, resampleMethod);

                      

                        currentDocument.resizeCanvas(width, height, AnchorPosition.MIDDLECENTER);

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