0 Replies Latest reply on Apr 8, 2013 12:21 AM by andreso1976

    Merging two png files to one

    andreso1976

      Can somebody help me modify thist script?

       

      I need merge two png files from two different folders to third folder as png, folders have same number of files but names are  different. Files must merged with alphapetical order.

      sorry my bad english

       

      folder A  / filename_K001.png

      folder B  / diffrent_filename_m01.png

      folder C / diffrent_filename_m01.png (same name as folder B files)

       

      this script want that file names in folders are identical.

       


      #target photoshop

      function main(){

      var dlg=

      "dialog{text:'Script Interface',bounds:[100,100,650,310],"+

      "panel0:Panel{bounds:[10,10,540,210] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+

      "statictext0:StaticText{bounds:[190,10,360,27] , text:'Merge Files' ,properties:{scrolling:undefined,multiline:undefined}},"+

      "panel1:Panel{bounds:[10,30,520,160] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+

      "statictext1:StaticText{bounds:[10,10,70,30] , text:'Folder A' ,properties:{scrolling:undefined,multiline:undefined}},"+

      "foldera:EditText{bounds:[80,10,430,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+

      "Browse1:Button{bounds:[440,10,501,31] , text:'<<' },"+

      "statictext2:StaticText{bounds:[10,40,70,57] , text:'Folder B' ,properties:{scrolling:undefined,multiline:undefined}},"+

      "folderb:EditText{bounds:[80,40,430,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+

      "Browse2:Button{bounds:[440,40,500,61] , text:'<<' },"+

      "statictext3:StaticText{bounds:[10,100,70,120] , text:'Output' ,properties:{scrolling:undefined,multiline:undefined}},"+

      "folderd:EditText{bounds:[80,100,430,120] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+

      "Browse4:Button{bounds:[440,100,501,120] , text:'>>' }},"+

      "Process:Button{bounds:[10,170,260,190] , text:'Process' },"+

      "button4:Button{bounds:[270,170,520,190] , text:'Cancel' }}};"

      var win = new Window(dlg,'Merge Files');

      win.center();

      win.panel0.panel1.foldera.enabled=false;

      win.panel0.panel1.folderb.enabled=false;

      win.panel0.panel1.folderd.enabled=false;

       


      win.panel0.panel1.Browse1.onClick = function() {

      inputFolder1 = Folder.selectDialog("Please select the folder with Files A to process");  

      if(inputFolder1 !=null){

      win.panel0.panel1.foldera.text =  decodeURI(inputFolder1.fsName);

      }

      }

      win.panel0.panel1.Browse2.onClick = function() {

      inputFolder2 = Folder.selectDialog("Please select the folder with Files B to process");  

      if(inputFolder2 !=null){

      win.panel0.panel1.folderb.text =  decodeURI(inputFolder2.fsName);

      }

      }

      win.panel0.panel1.Browse4.onClick = function() {

      outputFolder = Folder.selectDialog("Please select the output folder");  

      if(outputFolder !=null){

      win.panel0.panel1.folderd.text =  decodeURI(outputFolder.fsName);

      }

      }

      win.panel0.Process.onClick = function(){

      if(win.panel0.panel1.foldera.text == ''){

      alert("Folder A has not been selected!");

      return;

      }

      if(win.panel0.panel1.folderb.text == ''){

      alert("Folder B has not been selected!");

      return;

      }

      if(win.panel0.panel1.folderd.text == ''){

      alert("Output folder has not been selected!");

      return;

      }

      win.close(1);

      processDocuments();

      }

      win.show();

      function processDocuments(){

      var fileListA = inputFolder1.getFiles("*.png");

      for (var a in fileListA){

      var file = fileListA[a];

      var fileb = File(inputFolder2+"/"+file.name);

      if(!fileb.exists) continue;

      var saveFile = File(outputFolder+"/"+file.name.replace(/\.[^\.]+$/, '') +".tif");

      open(file);

      placeFile(fileb);

      rasterLayer();

      SaveTIFF(saveFile);

      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

      }

      }

      }

      main();

      function placeFile(placeFile) {

      var desc21 = new ActionDescriptor();

      desc21.putPath( charIDToTypeID('null'), new File(placeFile) );

      desc21.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );

      var desc22 = new ActionDescriptor();

      desc22.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );

      desc22.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );

      desc21.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc22 );

      executeAction( charIDToTypeID('Plc '), desc21, DialogModes.NO );

      };

      function rasterLayer() {

      var desc9 = new ActionDescriptor();

      var ref4 = new ActionReference();

      ref4.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

      desc9.putReference( charIDToTypeID('null'), ref4 );

      executeAction( stringIDToTypeID('rasterizeLayer'), desc9, DialogModes.NO );

      };

      function SaveTIFF(saveFile){

      tiffSaveOptions = new TiffSaveOptions();

      tiffSaveOptions.embedColorProfile = true;

      tiffSaveOptions.transparency=true;

      tiffSaveOptions.interleaveChannels=true;

      tiffSaveOptions.alphaChannels = false;

      tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;

      activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);

      }