Skip to main content
Inspiring
April 6, 2023
Answered

Why my 16 bit psd image is save as 48 bit png image when I use js script ?

  • April 6, 2023
  • 1 reply
  • 786 views

I use those js scripts.

This script just does "saveAs png exporting", but it always saves my 16 bit psd image as 48 bit png file.

var doc = activeDocument;
var exportPath = doc.fullName.toString().replace(/\.psd$/, '.png');
var newDoc = doc.duplicate();

fileObj = new File( exportPath )
pngOpt = new PNGSaveOptions();
pngOpt.interlaced = false;

activeDocument.saveAs(fileObj, pngOpt, true, Extension.LOWERCASE);

newDoc.close(SaveOptions.DONOTSAVECHANGES);

 

 

and this script, it just does what I need. It saves my 16 bit psd image as 24 bit png image(or 32 bit png image if  it contains alpha channel.).

preferences.rulerUnits = Units.PIXELS;

var doc = activeDocument;
var exportPath = doc.fullName.toString().replace(/\.psd$/, '.png');

var newDoc = doc.duplicate();

var webOpt = new ExportOptionsSaveForWeb();
webOpt.format = SaveDocumentType.PNG;
webOpt.PNG8 = false; // PNG-24

var newFile = new File(exportPath);
newDoc.exportDocument(newFile, ExportType.SAVEFORWEB, webOpt);

newDoc.close(SaveOptions.DONOTSAVECHANGES);

 
I don't know why 1st script always makes 48 bit png image.

Is it caused by limitation of "saveAs" command? I need to use saveforweb to make 24 bit png image?

This topic has been closed for replies.
Correct answer D Fosse

Just different notation.

 

16 bits per channel x 3 = 48 bits total.

 

If you need to convert to 8 bits per channel you need to invoke Image > Mode somewhere in your script.

 

Save for web automatically and always converts to 8 bpc (16 bit makes no sense for web).

1 reply

D Fosse
Community Expert
D FosseCommunity ExpertCorrect answer
Community Expert
April 6, 2023

Just different notation.

 

16 bits per channel x 3 = 48 bits total.

 

If you need to convert to 8 bits per channel you need to invoke Image > Mode somewhere in your script.

 

Save for web automatically and always converts to 8 bpc (16 bit makes no sense for web).

Inspiring
April 6, 2023

ah thank you. I just misunderstood bit depth thing. I edited my image in 16 Bits/channel mode so if I export them it should be 48 bit png image. I didn't know save for web exporting always makes 8 Bits mode image.