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

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

Engaged ,
Jan 20, 2016 Jan 20, 2016

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
677
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

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

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

Hi,

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

img-size.PNG

Regards,

Chetna

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

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

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

Moving the thread to Photoshop Scripting for further assistance.

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

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