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

Please edit this script so it saves PNG files?

Participant ,
Jun 10, 2017 Jun 10, 2017

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); 

TOPICS
Actions and scripting

Views

1.1K

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
Adobe
Community Expert ,
Jun 10, 2017 Jun 10, 2017

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?

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 ,
Jun 10, 2017 Jun 10, 2017

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

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 ,
Jun 10, 2017 Jun 10, 2017

Copy link to clipboard

Copied

Um... just a PNG with an alpha chan?

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 ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

Thanks but this script dose not seem to work?

I get this error...

zh9oS3.jpg

I am 100% sure I copied everything correctly?

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
Advisor ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

That 'M' at the end of the line should be a semicolon ->  ;

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
Engaged ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

LATEST

Hi,

Change M to ;  at end of Line 24.

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