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

Help with script saving PNG.. currently only says as 72DPI.. how can I make it retain the DPI?

Participant ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

Hi there... I have a script I can run that will save a PNG of the current visiable layers, and then increment the file name. I use this script inside actions to allow me ot save out files during edits.

 

This is my current script.

var saveFolder = new Folder( "d:\\PathTo\\SaveFolder" );  
var saveExt = 'png';  
var saveSufixStart = '_';  
var saveSufixLength = 3;  
// End of user options   
//==========================================   
  
var docName = decodeURI ( activeDocument.name );  
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];  
var saveName = docName[ 1 ]; // activeDocument name with out ext  
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix  
  
var saveNumber = files.length + 1;  
//alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));  
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );  
sfwPNG24( saveFile, 80 );  
//activeDocument.saveAs( saveFile, jpgSaveOptions ,true ,Extension.LOWERCASE);  
  
function zeroPad ( num, digit ) {   
   var tmp = num.toString();   
   while (tmp.length < digit) { tmp = "0" + tmp;}   
   return tmp;  
}  
  
function sfwPNG24( saveFile, quality ) {  
    var pngOpts = new ExportOptionsSaveForWeb;  
    pngOpts.format = SaveDocumentType.PNG;  
    pngOpts.PNG8 = false;  
    pngOpts.transparency = true;  
    pngOpts.interlaced = false;  
    pngOpts.quality = quality;  
    activeDocument.exportDocument( new File( saveFile ), ExportType.SAVEFORWEB ,pngOpts);  
}  

I had this made for me as I have zero understanding about scripting and programming.. I think the problem is the "ExportType.SAVEFORWEB"?

 

Basically if I have

  • 800DPI image
  • 2119x2883 pix
  • 6.73x9.15cm

I want it to stay that way... at the moment the script is outputting this...

  • 72DPI
  • 2119x2883 pix
  • 74.75x101.71cm

 

How would I midify this script to retain the existing DPI and print size of a document?

 

Thank you for any help you may have.

 

TOPICS
Actions and scripting , Windows

Views

380

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

Community Expert , Sep 18, 2022 Sep 18, 2022

@abUSER23 â€“ OK, I managed to look at this earlier than expected, try this:

 

var saveFolder = new Folder( "d:\\PathTo\\SaveFolder" );  
var saveExt = 'png';  
var saveSufixStart = '_';  
var saveSufixLength = 3;  
// End of user options   
  
var docName = decodeURI ( activeDocument.name );  
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];  
var saveName = docName[ 1 ]; // activeDocument name with out ext  
va
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

That is correct, the Save for Web code needs to be swapped out for a standard Save As code in order to retain the resolution metadata.

 

Just for the record, the PNG-pHYs specification does not use pixels per inch, it uses pixels per meter, so the saved resolution will be 31496 ppm, which Photoshop "translates" into a PPI value for display (314.96 cm x 2.54 cm [metric to inch] = 799.9984 ppi, rounded to 800 ppi).

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
Participant ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

thank you... but I have no diea how to chaneg this... what would the correct code be for the behaviour I am looking for?

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
Community Expert ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

I'll look at the code this evening if nobody has helped before then.

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
Participant ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

thanks for your time.

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
Community Expert ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

@abUSER23 â€“ OK, I managed to look at this earlier than expected, try this:

 

var saveFolder = new Folder( "d:\\PathTo\\SaveFolder" );  
var saveExt = 'png';  
var saveSufixStart = '_';  
var saveSufixLength = 3;  
// End of user options   
  
var docName = decodeURI ( activeDocument.name );  
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];  
var saveName = docName[ 1 ]; // activeDocument name with out ext  
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix  
  
var saveNumber = files.length + 1;  
//alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));  
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );  
saveAsPNG(saveFile, 9);  
  
function zeroPad ( num, digit ) {   
   var tmp = num.toString();   
   while (tmp.length < digit) { tmp = "0" + tmp;}   
   return tmp;  
}

function saveAsPNG(saveFile, quality) { 
    pngOpts = new PNGSaveOptions();
    pngOpts.compression = quality; //0-9
    pngOpts.interlaced = false;
    activeDocument.saveAs(File(saveFile), pngOpts, true); 
}

 

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
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

@abUSER23 - So how did the updated script go?

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
Participant ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

Sorry... for some reason I missed the notification email that there was a new reply.

 

I just tested the script and it apears to bne working as I hoped. Just saved a 800DPI image.. and the resulting png was the correct size,pixel count,dpi.... thanks man.

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
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

LATEST

You're welcome, notifications have been spotty for weeks, which is why I followed up.

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