Copy link to clipboard
Copied
Hi there... I have this code for a script that saves incremental files as JPG.... can someone please edit it so it saves as PNG insatead?
Thanks!
// This script will save the active document to a folder with an incremental sufix
// Change the options below to match your needs
var saveFolder = new Folder( 'C:\\test' );
var saveExt = 'jpg';
var saveSufixStart = '_';
var saveSufixLength = 3;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 10;
// End of user options
//==========================================
function zeroPad ( num, digit ){
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp;}
return tmp;
}
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 );
activeDocument.saveAs( saveFile, jpgSaveOptions ,true ,Extension.LOWERCASE);
Copy link to clipboard
Copied
I can’t script, however questions that spring to mind include:
Save or Export As or Export Save for Web?
Compression, Interlacing, PNG8 or PNG24 or PNG24+Alpha and if transparent, what options for matte etc?
Can you show the options in a screen capture from the user interface?
Copy link to clipboard
Copied
Hi abUSER23,
What kind of png – png8 or png24?
Save for Web or Save as?
untestet, but should do the job
var saveFolder = new Folder( 'C:\\test' );
var saveExt = 'png';
var saveSufixStart = '_';
var saveSufixLength = 3;
/*
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 10;
*/
// 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 )M
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);
}
Have fun
Copy link to clipboard
Copied
Um... just a PNG with an alpha chan?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That 'M' at the end of the line should be a semicolon -> ;
Copy link to clipboard
Copied
Hi,
Change M to ; at end of Line 24.