Thank you so much for the script, I am wondering If could you little amend script for me? I have another script that works with batching image processor please see below but this is not working well for background removel. What is want is with your script could you please add batch image process as my previous script have with some options? currently, script saves image in a folder called Final, I want form new script to save two variations of sizes 500x500px And another folder with 3000x3000px. so there will be two folders Thank you so much for your precious help. Here is my old script: #target photoshop cTID = function(s) { return app.charIDToTypeID(s); }; sTID = function(s) { return app.stringIDToTypeID(s); }; /***************************************** * Remove background script ****************************************/ var prefs = new Object(); var box = new Window('dialog', "Remove background from coins by fiverr.com/babloo"); box.panel0 = box.add('panel', undefined, "Select folder to process"); var browseGrp = box.panel0.add('group', undefined); browseGrp.orientation = 'row'; var folderpathText = browseGrp.add('edittext', undefined, " "); folderpathText.preferredSize = [300, 20]; box.panel0.orientation = 'column'; box.panel0.alignChildren = 'left'; box.panel0.margins = 10; box.panel0.browseBtn = browseGrp.add('button', undefined, "Browse", { name: 'Browse' }); box.panel0.browseBtn.onClick = function() { selectFolder(); }; box.group = box.add('group', undefined); box.group.orientation = 'row'; box.group.text1 = box.group.add('statictext', undefined, "Press OK to confirm"); box.group.okBtn = box.group.add('button', undefined, "OK", { name: 'ok' }); box.group.cancelBtn = box.group.add('button', undefined, "Cancel", { name: 'cancel' }); box.center(); box.result = box.show(); function selectFolder() { prefs.imageFolder = Folder.selectDialog("Select the folder to process"); folderpathText.text = decodeURI(prefs.imageFolder); if(folderpathText.text == "null") folderpathText.text = "No folder selected"; } if (box.result == 1) { if (prefs.imageFolder != null) processFolder(prefs.imageFolder); alert("All files are processed successfully and saved in final folder"); } function processFolder(folder) { var fileList = folder.getFiles(/\.(jpg)$/i); var saveFolder = Folder(decodeURI(folder) + "/Final"); if (!saveFolder.exists) saveFolder.create(); for (var i = 0; i < fileList.length; i++) { var file = fileList; if (file instanceof File) { var doc = open(file); var docName = doc.name; docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/) : docName = [docName, docName]; var layer = doc.activeLayer; var nLayer = layer.duplicate(); layer.remove(); RemoveBG(doc); doc.crop(doc.activeLayer.bounds); var l = doc.artLayers.add(); l.isBackgroundLayer = true; doc.resizeImage(UnitValue(2500,"px"),UnitValue(2500,"px"),null,ResampleMethod.BICUBIC); SaveJPG (doc, saveFolder, docName[1],"2500X2500"); doc.resizeImage(UnitValue(500,"px"),UnitValue(500,"px"),null,ResampleMethod.BICUBIC); SaveJPG (doc, saveFolder, docName[1],"500X500"); doc.close(SaveOptions.DONOTSAVECHANGES); } } } function SaveJPG(doc, folder, name,suffix) { var saveFile = new File(folder + "/" + name +"_" +suffix+".jpg"); var saveOptions = new JPEGSaveOptions(); saveOptions.embedColorProfile = true; saveOptions.formatOptions = FormatOptions.STANDARDBASELINE; saveOptions.matte = MatteType.NONE; saveOptions.quality = 8 doc.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE); } function getLayerByName(name){ for(var x = 0; x < app.activeDocument.layers.length; x++){ var layer = app.activeDocument.layers ; if(layer.name == name){ return layer; } } return null; } function RemoveBG(doc) { function selectLayer(){ var layer = getLayerByName ("Layer 0"); layer.visible = true; doc.activeLayer = layer; }; function magicWand(x,y,t,a,c,s) { if(arguments.length < 2) return;// make sure have x,y if(undefined == t) var t = 32;// set defaults of optional arguments if(undefined == a) var a = true; if(undefined == c) var c = false; if(undefined == s) var s = false; var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') ); desc.putReference( charIDToTypeID('null'), ref ); var positionDesc = new ActionDescriptor(); positionDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Rlt'), x ); positionDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Rlt'), y ); desc.putObject( charIDToTypeID('T '), charIDToTypeID('Pnt '), positionDesc ); desc.putInteger( charIDToTypeID('Tlrn'), t); desc.putBoolean( charIDToTypeID('Mrgd'), s ); if(!c) desc.putBoolean( charIDToTypeID( "Cntg" ), c); desc.putBoolean( charIDToTypeID('AntA'), a ); executeAction( charIDToTypeID('setd'), desc, DialogModes.NO ); }; function step3() { //var sColor = new SolidColor; //sColor.rgb.hexValue = 'ffffff'; //doc.selection.fill(sColor,); executeAction(cTID('Dlt '), undefined, DialogModes.NO); }; function step4(enabled, withDialog) { app.activeDocument.selection.deselect(); }; //selectLayer (); magicWand(170,108,60,true,true,false); step3(); step4(); };
... View more