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
I want it to stay that way... at the moment the script is outputting this...
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.
@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
...
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).
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?
Copy link to clipboard
Copied
I'll look at the code this evening if nobody has helped before then.
Copy link to clipboard
Copied
thanks for your time.
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);
}
Copy link to clipboard
Copied
@abUSER23 - So how did the updated script go?
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.
Copy link to clipboard
Copied
You're welcome, notifications have been spotty for weeks, which is why I followed up.