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

Photoshop scripting: save JPEG with different canvas size than document

New Here ,
Jan 28, 2022 Jan 28, 2022

I'm writing a Photoshop script (in javascript) to save a copy of the document as a JPEG and I would like to save it with a smaller canvas than the photoshop document, without changing the document I'm in.

 

My current PS document is 3600x3600 at 300dpi. I would like the script to save two JPEG's, one at 2000x2000 at 300dpi and one at 1000x1000 at 72dpi, while keeping the original document at 3600x3600 at 300dpi.

 

Is this possible with `JPEGSaveOptions` or otherwise? As I hunt thru docs and forums, it looks like doing so requires changing the app.document, doing the outputs, then reverting the app.document to the original.

 

You need to ask program questions in the forum for the program you are using
To ask in the forum for your program please start at https://community.adobe.com/
Moving from Using the Community (which is about the forums) to the correct forum... Mod

709
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
Mentor ,
Jan 28, 2022 Jan 28, 2022

Export As already has this feature built in. Can you use that?
Although, now that i think about it, six years after its introduction, we're still unable to add Export As to an Action, so i'm wondering if that will restrict its scripting usage too?
And don't ask me why it can't be added to an Action. We've been begging since day one.

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
New Here ,
Jan 28, 2022 Jan 28, 2022

I need to do this in the javascript, the script is actually being called repetatively on multiple layers.

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

The `JPEGSaveOptions`don't change the size of the image, you have to do that with other functions like resizeImage, then make sure you saveas two different file names.

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

The standard Photoshop object model JS reference does not offer a resize ability in ExportOptionsSaveForWeb – however, if you use scripting listener plug-in the recorded action manager code does include this information (plus a whole lot more, approx 250 lines of raw code for a single export). Although the GUI shows both % and px sizing, the code records the resize as a % value.

 

So you have two options that I can think of:

 

1) Script duplicating the doc (or reverting or using history snapshots etc), resizing, saving, closing/reverting without saving

2) Script save for web to produce the image assets at different sizes, this will not retain resolution metadata, so if this is critical save as would be needed

 

A similar discussion took place where I explored Generator via scripting, however, it is not robust and this was more for an exercise than anything else:

 

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 28, 2022 Jan 28, 2022
LATEST

BTW, I just tested the Clean SL script and it reduced the raw recording of 250 lines down to 116.  Looking at the result it may be possible to make further manual optimisations.

 

As the clean SL output is in a function, you only need the main function once and you can just change the H and V scale parameter values each time the function is called.

 

Of course this is document based, not layer based so you would need to do more work to isolate the layer visibility or something else to get the results you require.

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