Mass removing background using photoshop script
Hello there
Need help with this script:
var sourceFolder = Folder("C:\\ps\\src");
if (sourceFolder != null)
{
var fileList = sourceFolder.getFiles();
//comment the above line and uncomment the following line to filter specific file types. the script will not work if you have any non-image file in the src folder so try filtering files types if the script fails.
// var fileList = sourceFolder..getFiles(/\.(jpg|tif|psd|crw|cr2|nef|dcr|dc2|raw|heic)$/i);
}
for(var a = 0 ;a < fileList.length; a++){
app.open(fileList[a]);
// Select subject
var idautoCutout = stringIDToTypeID( "autoCutout" );
var desc01 = new ActionDescriptor();
var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
desc01.putBoolean( idsampleAllLayers, false );
try{
executeAction( idautoCutout, desc01, DialogModes.NO );
}
catch(err){}
// Invert the selection
app.activeDocument.selection.invert();
// Create a color to be used with the fill command
var colorRef = new SolidColor
colorRef.rgb.red = 0
colorRef.rgb.green = 0
colorRef.rgb.blue = 0
// Now apply fill to the current selection
app.activeDocument.selection.fill(colorRef)
//enter path for where you want the file saved
var saveFolder = new Folder("C:\\ps\\out");
var fileName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
sfwPNG24 (new File(saveFolder +'/' + fileName + '.png'),12);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//fileList[a].remove();
}
function sfwPNG24(saveFile){
var pngOpts = new PNGSaveOptions;
pngOpts.transparency = true
pngOpts.compression = 9;
pngOpts.interlaced = false;
activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);
}
Right now script works and it saves files from folder to .png
But i need a transparent background for my images..
Need something that can delete selected pixels after this:
app.activeDocument.selection.invert();
In Photoshop there is button "Delete" (Edit -> Clear), when you press this it deletes pixels in selected area. I need this in script. How to do this?
Maybe i need somehow to simulate
