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

Trouble using script to save PSD as PNG

Community Expert ,
Feb 20, 2024 Feb 20, 2024

Hi all, 

I have the following code to resize and save a PSD as a PNG. It was working fine, and still works for some psds, but frequently I am getting a user Save a Copy prompt at the doc.saveAs line. Is there something I'm missing? 

 

var path = File.openDialog().fsName;
    app.rulerUnits = Units.PIXELS;
    var pngOpts = new PNGSaveOptions;
    try {
        var doc = app.open(File(path));
    } catch(e) {
        alert("Could not open psd file " + path + ". " + e);
        return;
    }
    if (doc.width > 1500) {
        doc.resizeImage(1500, null);
    }
    var goodPath = path.replace(/psd|b$/gi,"png");
    doc.saveAs(File(goodPath), pngOpts, true);
    doc.close(SaveOptions.DONOTSAVECHANGES);

 

TOPICS
Actions and scripting
502
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
Community Expert ,
Feb 20, 2024 Feb 20, 2024

Do you have legacy save as set in your file handling preferences?

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 ,
Feb 20, 2024 Feb 20, 2024

I did not. I tried enabling it; same result. Which should it be set at? 

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 ,
Feb 20, 2024 Feb 20, 2024

OK, so that wasn't the answer for the script.

 

It needs to be set at whatever your preference is!  :]

 

https://helpx.adobe.com/photoshop/using/saving-images.html#save-as

 

When you get the prompt, what colour mode and bit depth is the file?

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 ,
Feb 27, 2024 Feb 27, 2024

Sorry for the lag. Color profile shows ICC. Sorry, where do I find the bit depth? It shows CMYK/8 in the file name.

brianp311_0-1709062140804.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
Community Expert ,
Mar 03, 2024 Mar 03, 2024
LATEST

The CMYK/8 indicates that this is 8 BPC (also found under the Image > Mode menu).

 

PNG doesn't support CMYK colour mode, you need to convert a copy to RGB mode, usually the sRGB profile as the lowest common denominator.

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