Copy link to clipboard
Copied
Hi, I have a bunch of images just like attached below in terms of size and feel, I just want to make an action to remove background size and gradients effects are same just like examples I have attached here, so there are any possibilities to make such kind of action to auto remove all background?
Thanks in advance
FINAL RESULT that I want
On CC 2017 this provides halfway decent results for the test files (utilising the four-corner-Magic-Wand-Selection as proposed by JJMack):
...
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
myDocument.selection.deselect();
// magic wand selection;
magicWandTool (10,10);
magicWandTool (myDocument.width-10,10);
magicWandTool (myDocument.width-10
Copy link to clipboard
Copied
You do not start what size and resolution your images are. If the vary all over the place dealing with size can be difficult in actions. Also if you files may be layered documents actions can not loop through the document layers and remover backgrounds from all raster layers.
An action could process all the image files you want to batch by first flattening document open in a batch to make have just a background layer. Convert the background layers to a normal layer. Use the Magic want tool in contiguous mode sampling the four corners to try to select the type of backgrounds you show in your examples. Or Stroke the edges with the quick selection tool. Clear that selection and trim the transparency created to tightly crop to the object bounds. Then increase the canvas size so when you save a jpeg there white space on four size. The main problem is the action does not know the images resolution so it has no way to know the number of pixels it should increase the canvas size by for that white space you seem to want. You would override the Actions save as Jpeg on you desktop to save the output jpeg where you want them.
Download this stroke quick selection tool it adds 150 px on sides 1/2" at 300DPI TrimAndAdd.atn
Crafting Actions Package UPDATED Aug 10, 2014 Added Conditional Action steps to Action Palette Tips.
Contains
Copy link to clipboard
Copied
I use CC 2014 it seems like the are bugs in CC 2015.5 and CC 2017 when you try to stroke a path with the quick selection tool in an Action those Photoshop versions display an "Program Error" pop up message. When I manually try to stroke a path with the quick selection tool CC 2015.5 pop up the Program error window CC 2017 on the other hand when I try to stroke a path Photoshop Crashes.
There is a Problem trying to use the Magic wand instead The selection set were not very good compared the Stroking with the Quick selection tool in CC 2014 here is what I see in CC 2014
Copy link to clipboard
Copied
Thanks JJMack for your interest and help, I will check and test stroke quick selection tool. It seems useful and interesting.
Copy link to clipboard
Copied
On CC 2017 this provides halfway decent results for the test files (utilising the four-corner-Magic-Wand-Selection as proposed by JJMack):
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
myDocument.selection.deselect();
// magic wand selection;
magicWandTool (10,10);
magicWandTool (myDocument.width-10,10);
magicWandTool (myDocument.width-10,myDocument.height-10);
magicWandTool (10,myDocument.height-10);
// invert selection;
myDocument.selection.invert();
// layer via copy;
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
var thisLayer = myDocument.activeLayer;
// hide others;
hideOthers ();
// remove potential dirt;
loadTransparency(false);
myDocument.selection.contract(10);
myDocument.selection.expand(15);
myDocument.selection.invert();
myDocument.selection.clear();
myDocument.selection.deselect();
// trim with 4px edge;
cropTo(thisLayer.bounds[0]-4, thisLayer.bounds[1]-4, thisLayer.bounds[2]+4, thisLayer.bounds[3]+4);
// reset ruler;
app.preferences.rulerUnits = originalRulerUnits;
};
////// function //////
function magicWandTool (theX, theY) {
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idmagicWandTool = stringIDToTypeID( "magicWandTool" );
ref5.putClass( idmagicWandTool );
desc12.putReference( idnull, ref5 );
/* var iddontRecord = stringIDToTypeID( "dontRecord" );
desc12.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc12.putBoolean( idforceNotify, true );*/
executeAction( idslct, desc12, DialogModes.NO );
// =======================================================
var idAddT = charIDToTypeID( "AddT" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc4.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idVrtc, idPxl, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc4.putObject( idT, idPnt, desc5 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc4.putInteger( idTlrn, 36 );
var idAntA = charIDToTypeID( "AntA" );
desc4.putBoolean( idAntA, true );
executeAction( idAddT, desc4, DialogModes.NO );/*
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref1.putProperty( idChnl, idfsel );
desc2.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc3 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idVrtc, idPxl, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc2.putObject( idT, idPnt, desc3 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc2.putInteger( idTlrn, 36 );
var idMrgd = charIDToTypeID( "Mrgd" );
desc2.putBoolean( idMrgd, true );
var idAntA = charIDToTypeID( "AntA" );
desc2.putBoolean( idAntA, true );
executeAction( idsetd, desc2, DialogModes.NO );*/
};
////// hide others //////
function hideOthers () {
// hide others;
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
list1.putReference( ref1 );
desc2.putList( idnull, list1 );
var idTglO = charIDToTypeID( "TglO" );
desc2.putBoolean( idTglO, true );
executeAction( idShw, desc2, DialogModes.NO );
};
////// load transparency //////
function loadTransparency (theInvert) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc3.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var ref3 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref3.putEnumerated( idChnl, idChnl, idTrsp );
desc3.putReference( idT, ref3 );
desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( idsetd, desc3, DialogModes.NO );
};
////// crop //////
function cropTo (x1, y1, x2, y2) {
// =======================================================
var idCrop = charIDToTypeID( "Crop" );
var desc7 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc8 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idTop, idPxl, y1 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idLeft, idPxl, x1);
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idBtom, idPxl, y2 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idRght, idPxl, x2 );
var idRctn = charIDToTypeID( "Rctn" );
desc7.putObject( idT, idRctn, desc8 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc7.putUnitDouble( idAngl, idAng, 0.000000 );
var idDlt = charIDToTypeID( "Dlt " );
desc7.putBoolean( idDlt, false );
var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" );
desc7.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );
var idCnsP = charIDToTypeID( "CnsP" );
desc7.putBoolean( idCnsP, false );
executeAction( idCrop, desc7, DialogModes.NO );
};
Copy link to clipboard
Copied
By the way: Compliments on posting three fairly different sample-files for illustrating the variance and for testing right away.
Sometimes posters seem tempted to write lots of text instead of posting images that could clarify the issue easily.
Copy link to clipboard
Copied
Thanks a lot c.pfaffenbichler its working perfectly I am so happy to get this!!! I wish I can learn js coding because I love this result.
Copy link to clipboard
Copied
Adding the white canvas to the script
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
myDocument.selection.deselect();
// magic wand selection;
magicWandTool (10,10);
magicWandTool (myDocument.width-10,10);
magicWandTool (myDocument.width-10,myDocument.height-10);
magicWandTool (10,myDocument.height-10);
// invert selection;
myDocument.selection.invert();
// layer via copy;
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
var thisLayer = myDocument.activeLayer;
// hide others;
hideOthers ();
// remove potential dirt;
loadTransparency(false);
myDocument.selection.contract(10);
myDocument.selection.expand(15);
myDocument.selection.invert();
myDocument.selection.clear();
myDocument.selection.deselect();
// trim with 4px edge;
cropTo(thisLayer.bounds[0]-4, thisLayer.bounds[1]-4, thisLayer.bounds[2]+4, thisLayer.bounds[3]+4);
addPXtoCanvas (300,300);
activeDocument.flatten();
// reset ruler;
app.preferences.rulerUnits = originalRulerUnits;
};
////// function //////
function magicWandTool (theX, theY) {
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idmagicWandTool = stringIDToTypeID( "magicWandTool" );
ref5.putClass( idmagicWandTool );
desc12.putReference( idnull, ref5 );
/* var iddontRecord = stringIDToTypeID( "dontRecord" );
desc12.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc12.putBoolean( idforceNotify, true );*/
executeAction( idslct, desc12, DialogModes.NO );
// =======================================================
var idAddT = charIDToTypeID( "AddT" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc4.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idVrtc, idPxl, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc4.putObject( idT, idPnt, desc5 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc4.putInteger( idTlrn, 36 );
var idAntA = charIDToTypeID( "AntA" );
desc4.putBoolean( idAntA, true );
executeAction( idAddT, desc4, DialogModes.NO );/*
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref1.putProperty( idChnl, idfsel );
desc2.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc3 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idVrtc, idPxl, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc2.putObject( idT, idPnt, desc3 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc2.putInteger( idTlrn, 36 );
var idMrgd = charIDToTypeID( "Mrgd" );
desc2.putBoolean( idMrgd, true );
var idAntA = charIDToTypeID( "AntA" );
desc2.putBoolean( idAntA, true );
executeAction( idsetd, desc2, DialogModes.NO );*/
};
////// hide others //////
function hideOthers () {
// hide others;
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
list1.putReference( ref1 );
desc2.putList( idnull, list1 );
var idTglO = charIDToTypeID( "TglO" );
desc2.putBoolean( idTglO, true );
executeAction( idShw, desc2, DialogModes.NO );
};
////// load transparency //////
function loadTransparency (theInvert) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc3.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var ref3 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref3.putEnumerated( idChnl, idChnl, idTrsp );
desc3.putReference( idT, ref3 );
desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( idsetd, desc3, DialogModes.NO );
};
////// crop //////
function cropTo (x1, y1, x2, y2) {
// =======================================================
var idCrop = charIDToTypeID( "Crop" );
var desc7 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc8 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idTop, idPxl, y1 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idLeft, idPxl, x1);
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idBtom, idPxl, y2 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idRght, idPxl, x2 );
var idRctn = charIDToTypeID( "Rctn" );
desc7.putObject( idT, idRctn, desc8 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc7.putUnitDouble( idAngl, idAng, 0.000000 );
var idDlt = charIDToTypeID( "Dlt " );
desc7.putBoolean( idDlt, false );
var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" );
desc7.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );
var idCnsP = charIDToTypeID( "CnsP" );
desc7.putBoolean( idCnsP, false );
executeAction( idCrop, desc7, DialogModes.NO );
};
// =======================================================
function addPXtoCanvas (width, height) {
var idCnvS = charIDToTypeID( "CnvS" );
var desc11 = new ActionDescriptor();
var idRltv = charIDToTypeID( "Rltv" );
desc11.putBoolean( idRltv, true );
var idWdth = charIDToTypeID( "Wdth" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idWdth, idPxl, width );
var idHght = charIDToTypeID( "Hght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idHght, idPxl, height );
var idHrzn = charIDToTypeID( "Hrzn" );
var idHrzL = charIDToTypeID( "HrzL" );
var idCntr = charIDToTypeID( "Cntr" );
desc11.putEnumerated( idHrzn, idHrzL, idCntr );
var idVrtc = charIDToTypeID( "Vrtc" );
var idVrtL = charIDToTypeID( "VrtL" );
var idCntr = charIDToTypeID( "Cntr" );
desc11.putEnumerated( idVrtc, idVrtL, idCntr );
var idcanvasExtensionColorType = stringIDToTypeID( "canvasExtensionColorType" );
var idcanvasExtensionColorType = stringIDToTypeID( "canvasExtensionColorType" );
var idBckC = charIDToTypeID( "BckC" );
desc11.putEnumerated( idcanvasExtensionColorType, idcanvasExtensionColorType, idBckC );
executeAction( idCnvS, desc11, DialogModes.NO );
}
Copy link to clipboard
Copied
Just be warned that there may be images where the Script does not get a decent result (due to dirt in the background or especially large brightness variations for example).
Ideally you should control all the resulting files to make sure the operation did not go awry and keep your original images as a back-up.
Copy link to clipboard
Copied
That is why I stroked the edges with the quick selection tool. However there are bugs in cc2015.5 and cc 2017 doing that they produce program errors rather than selections....
The Quick selection tool produced better selections then the magic wand tool.
Copy link to clipboard
Copied
Yes that is little bit problem only for bright background or dirt in the background, but I can handle, So I just one problem if you can add save directory directly in the script?
currently, I run an action to open all images and then save as command and lastly run Batch image to select all images in the whole folder?
Copy link to clipboard
Copied
If you use CC 2014 you should be able the batch the action I posted. The process does not need to be scripted it is straight forward and can be recorded in an action. CC 2015.5 and CC 2017 have problem with stroking paths with the Quick selection tool. The script posted here that used the magic wand could be recorded as an action was well. The magic want tool does not work as well a the quick selection tool on the images you posted. In CC 2014 you can record both process in action and batch both. and keep the best files saved.
I posted my action batched you can see all in the screen captures I posted. The are bugs in CC 2015.5 and CC 2017 in this area.....
you can also use the script posted here in an action and add the save in the action. You co also add a prompt for the output folder and add the save as in the script.
Its all up to you.
With Xtools you can convert an action into a script however the action will work faster the the script.
Copy link to clipboard
Copied
Unfortunately, i have a problem with the action. When i try to run the action i got a message that's tell me "this function might be unavailable with your photoshop version" i run it with photoshop 2017 cc
Copy link to clipboard
Copied
mirza5313 wrote
Unfortunately, i have a problem with the action. When i try to run the action i got a message that's tell me "this function might be unavailable with your photoshop version" i run it with photoshop 2017 cc
Yes I have written many times my action will not run in Photoshop CC 2015.5 and CC 2017 the there are bugs in those version of Photoshop the error is not in the action. Are you using a Mac. The error you state you get is not the error I see on Windows there as I poster it is a Photoshop Program Error I see and posted in this thread.
Copy link to clipboard
Copied
This is not about script error that is related to action so I just want to save as action and batch image process can be included in this script to that I don't need to run an action the whole process can be done via script?
Copy link to clipboard
Copied
As I wrote you can record an action that uses the script posted in this thread in CC 2017 and add the save as in the action as the last step. Then batch that action. Without the save as step in the action you could use the image processor script and use the action in the Image processor. You could also record the process in the script as an Action in CC 2017 and batch it. You have many options. IMO you should be using CC 2014 there are too many issues in CC 2017 for me..... You can install previous version of Photoshop using the Creative Cloud Desktop Application.
Copy link to clipboard
Copied
Thanks, JJMack, I just got a script for Save command and working accurately:
var doc = app.activeDocument;
var filePath = activeDocument.fullName.path;
var pngFile = File(filePath + "/" + "myname.png");
pngSaveOptions = new PNGSaveOptions();
doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE);
So, there is no need to create an action for saving as a command.
Copy link to clipboard
Copied
How do you batch that script it you save as code looks like it always saves "myname.png"
Copy link to clipboard
Copied
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();
};
Copy link to clipboard
Copied
// 2017, use it at your own risk;
#target photoshop
// folder selection;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i)
};
// process the files;
if (theFiles.length > 0) {
var folder1 = theFolder+"/500x500";
var folder2 = theFolder+"/3000x3000";
if (Folder(folder1).exists == false) {Folder(folder1).create()};
if (Folder(folder2).exists == false) {Folder(folder2).create()};
for (var x = 0; x < theFiles.length; x++) {
processFile (theFiles
}
};
////// function //////
function processFile (theFile, folder1, folder2) {
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 10;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
// diplicate image;
var theOriginal = app.open(theFile);//app.activeDocument;
var theName = theOriginal.name.match(/(.*)\.[^\.]+$/)[1];
var myDocument = theOriginal.duplicate(theName, true);
app.activeDocument = theOriginal;
theOriginal.close();
// do stuff;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
myDocument.selection.deselect();
// magic wand selection;
magicWandTool (10,10);
magicWandTool (myDocument.width-10,10);
magicWandTool (myDocument.width-10,myDocument.height-10);
magicWandTool (10,myDocument.height-10);
// invert selection;
myDocument.selection.invert();
// layer via copy;
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
var thisLayer = myDocument.activeLayer;
// hide others;
hideOthers ();
// remove potential dirt;
loadTransparency(false);
myDocument.selection.contract(10);
myDocument.selection.expand(15);
myDocument.selection.invert();
myDocument.selection.clear();
myDocument.selection.deselect();
// trim with 4px edge;
cropTo(thisLayer.bounds[0]-1, thisLayer.bounds[1]-1, thisLayer.bounds[2]+1, thisLayer.bounds[3]+1);
// squaer;
myDocument.resizeCanvas(Math.max(myDocument.width, myDocument.height), Math.max(myDocument.width, myDocument.height), AnchorPosition.MIDDLECENTER);
//
myDocument.resizeImage(3000, 3000, myDocument.resolution, ResampleMethod.BICUBICAUTOMATIC);
myDocument.saveAs(new File(folder2 + "/" + theName + "_3000x3000.jpg"), jpegOptions, true);
myDocument.activeHistoryState = myDocument.historyStates[myDocument.historyStates.length-2];
myDocument.resizeImage(500, 500, myDocument.resolution, ResampleMethod.BICUBICAUTOMATIC);
myDocument.saveAs(new File(folder1 + "/" + theName + "_500x500.jpg"), jpegOptions, true);
// close;
myDocument.close(SaveOptions.DONOTSAVECHANGES);
// reset ruler;
app.preferences.rulerUnits = originalRulerUnits;
};
////// function //////
function magicWandTool (theX, theY) {
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idmagicWandTool = stringIDToTypeID( "magicWandTool" );
ref5.putClass( idmagicWandTool );
desc12.putReference( idnull, ref5 );
executeAction( idslct, desc12, DialogModes.NO );
// =======================================================
var idAddT = charIDToTypeID( "AddT" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc4.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idVrtc, idPxl, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc4.putObject( idT, idPnt, desc5 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc4.putInteger( idTlrn, 36 );
desc4.putBoolean( charIDToTypeID( "Cntg" ), true );
var idAntA = charIDToTypeID( "AntA" );
desc4.putBoolean( idAntA, true );
executeAction( idAddT, desc4, DialogModes.NO );
};
////// hide others //////
function hideOthers () {
// hide others;
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
list1.putReference( ref1 );
desc2.putList( idnull, list1 );
var idTglO = charIDToTypeID( "TglO" );
desc2.putBoolean( idTglO, true );
executeAction( idShw, desc2, DialogModes.NO );
};
////// load transparency //////
function loadTransparency (theInvert) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc3.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var ref3 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref3.putEnumerated( idChnl, idChnl, idTrsp );
desc3.putReference( idT, ref3 );
desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( idsetd, desc3, DialogModes.NO );
};
////// crop //////
function cropTo (x1, y1, x2, y2) {
// =======================================================
var idCrop = charIDToTypeID( "Crop" );
var desc7 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc8 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idTop, idPxl, y1 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idLeft, idPxl, x1);
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idBtom, idPxl, y2 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idRght, idPxl, x2 );
var idRctn = charIDToTypeID( "Rctn" );
desc7.putObject( idT, idRctn, desc8 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc7.putUnitDouble( idAngl, idAng, 0.000000 );
var idDlt = charIDToTypeID( "Dlt " );
desc7.putBoolean( idDlt, false );
var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" );
desc7.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );
var idCnsP = charIDToTypeID( "CnsP" );
desc7.putBoolean( idCnsP, false );
executeAction( idCrop, desc7, DialogModes.NO );
};
////// trim //////
function trimTransparent () {
// =======================================================
var idtrim = stringIDToTypeID( "trim" );
var desc11 = new ActionDescriptor();
var idtrimBasedOn = stringIDToTypeID( "trimBasedOn" );
var idtrimBasedOn = stringIDToTypeID( "trimBasedOn" );
var idTrns = charIDToTypeID( "Trns" );
desc11.putEnumerated( idtrimBasedOn, idtrimBasedOn, idTrns );
var idTop = charIDToTypeID( "Top " );
desc11.putBoolean( idTop, true );
var idBtom = charIDToTypeID( "Btom" );
desc11.putBoolean( idBtom, true );
var idLeft = charIDToTypeID( "Left" );
desc11.putBoolean( idLeft, true );
var idRght = charIDToTypeID( "Rght" );
desc11.putBoolean( idRght, true );
executeAction( idtrim, desc11, DialogModes.NO );
};
Copy link to clipboard
Copied
Thanks a lot, c.pfaffenbichler you are life-saving script worked and save two folders, just last request could you please amend script to save both of the folders files as PNG? I'll use more often the picture in .jpg with white background.
So, this script is also valid for jpg and another one which saves files as standard PNG
Thank you so much for your help!
Copy link to clipboard
Copied
That sound like an easy addition to make. You have code to save a "MyName.PNG" file why not look at the script c.pfaffenbichler just gave you and add the additional save as png. Learn a little so you can hack on scripts yourself. You will not always be able to find someone to hack a script for you.
Copy link to clipboard
Copied
Hello,
Thank you for sharing the know-how!
I do actually very similar job but in quite different part of the world and different coins.
I have already developed my own actions, very similar to above presented although I must admit-these seem to be more efficient.
Got some issues however: would it(above) work proprly in CS5? (thats my platform for now)
and how should I edit? Its the simple content of*.atn file?
I need to stay with basic adjustments layer /curves, intensity-color, brigtnes- just 3 of them fpr further corrections) AND-whats most
important to me-I have to do that exracting via layer masking.
Thx in advance for your help,
cheers,
Copy link to clipboard
Copied
You may want to start a new thread to discuss your particular issues.
Its the simple content of*.atn file?
The code needs to be saved as a jsx-file (a txt-file with the extension »jsx«) and placed in Photoshop’s Presets/Scripts-Folder.
important to me-I have to do that exracting via layer masking.
Then you could make the background layer a regular one, add the Layer Mask with Action Manager-code plus some more changes on the now useless
myDocument.selection.clear();
for example.
Copy link to clipboard
Copied
Below the log from my action(s):
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc4
SET desc4 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref3
SET ref3 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref3.PutIndex( idCmnd, 1 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref3.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref3.PutName( idASet, "TrimAndAdd" )
Call desc4.PutReference( idnull, ref3 )
Call objApp.ExecuteAction( idPly, desc4, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc5
SET desc5 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref4
SET ref4 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref4.PutIndex( idCmnd, 2 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref4.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref4.PutName( idASet, "TrimAndAdd" )
Call desc5.PutReference( idnull, ref4 )
Call objApp.ExecuteAction( idPly, desc5, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc6
SET desc6 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref5
SET ref5 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref5.PutIndex( idCmnd, 3 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref5.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref5.PutName( idASet, "TrimAndAdd" )
Call desc6.PutReference( idnull, ref5 )
Call objApp.ExecuteAction( idPly, desc6, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc7
SET desc7 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref6
SET ref6 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref6.PutIndex( idCmnd, 4 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref6.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref6.PutName( idASet, "TrimAndAdd" )
Call desc7.PutReference( idnull, ref6 )
Call objApp.ExecuteAction( idPly, desc7, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc8
SET desc8 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref7
SET ref7 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref7.PutIndex( idCmnd, 5 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref7.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref7.PutName( idASet, "TrimAndAdd" )
Call desc8.PutReference( idnull, ref7 )
Call objApp.ExecuteAction( idPly, desc8, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc9
SET desc9 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref8
SET ref8 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref8.PutIndex( idCmnd, 6 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref8.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref8.PutName( idASet, "TrimAndAdd" )
Call desc9.PutReference( idnull, ref8 )
Call objApp.ExecuteAction( idPly, desc9, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc10
SET desc10 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref9
SET ref9 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref9.PutIndex( idCmnd, 7 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref9.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref9.PutName( idASet, "TrimAndAdd" )
Call desc10.PutReference( idnull, ref9 )
Call objApp.ExecuteAction( idPly, desc10, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc11
SET desc11 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref10
SET ref10 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref10.PutIndex( idCmnd, 8 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref10.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref10.PutName( idASet, "TrimAndAdd" )
Call desc11.PutReference( idnull, ref10 )
Call objApp.ExecuteAction( idPly, desc11, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc12
SET desc12 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref11
SET ref11 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref11.PutIndex( idCmnd, 9 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref11.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref11.PutName( idASet, "TrimAndAdd" )
Call desc12.PutReference( idnull, ref11 )
Call objApp.ExecuteAction( idPly, desc12, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc13
SET desc13 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref12
SET ref12 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref12.PutIndex( idCmnd, 10 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref12.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref12.PutName( idASet, "TrimAndAdd" )
Call desc13.PutReference( idnull, ref12 )
Call objApp.ExecuteAction( idPly, desc13, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc14
SET desc14 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref13
SET ref13 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref13.PutIndex( idCmnd, 11 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref13.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref13.PutName( idASet, "TrimAndAdd" )
Call desc14.PutReference( idnull, ref13 )
Call objApp.ExecuteAction( idPly, desc14, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc15
SET desc15 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref14
SET ref14 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref14.PutIndex( idCmnd, 12 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref14.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref14.PutName( idASet, "TrimAndAdd" )
Call desc15.PutReference( idnull, ref14 )
Call objApp.ExecuteAction( idPly, desc15, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc16
SET desc16 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref15
SET ref15 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref15.PutIndex( idCmnd, 13 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref15.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref15.PutName( idASet, "TrimAndAdd" )
Call desc16.PutReference( idnull, ref15 )
Call objApp.ExecuteAction( idPly, desc16, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc17
SET desc17 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref16
SET ref16 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref16.PutIndex( idCmnd, 14 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref16.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref16.PutName( idASet, "TrimAndAdd" )
Call desc17.PutReference( idnull, ref16 )
Call objApp.ExecuteAction( idPly, desc17, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc18
SET desc18 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref17
SET ref17 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref17.PutIndex( idCmnd, 15 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref17.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref17.PutName( idASet, "TrimAndAdd" )
Call desc18.PutReference( idnull, ref17 )
Call objApp.ExecuteAction( idPly, desc18, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc19
SET desc19 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref18
SET ref18 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref18.PutIndex( idCmnd, 16 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref18.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref18.PutName( idASet, "TrimAndAdd" )
Call desc19.PutReference( idnull, ref18 )
Call objApp.ExecuteAction( idPly, desc19, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc20
SET desc20 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref19
SET ref19 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref19.PutIndex( idCmnd, 17 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref19.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref19.PutName( idASet, "TrimAndAdd" )
Call desc20.PutReference( idnull, ref19 )
Call objApp.ExecuteAction( idPly, desc20, dialogMode )
REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idPly
idPly = objApp.CharIDToTypeID( "Ply " )
DIM desc21
SET desc21 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idnull
idnull = objApp.CharIDToTypeID( "null" )
DIM ref20
SET ref20 = CreateObject( "Photoshop.ActionReference" )
DIM idCmnd
idCmnd = objApp.CharIDToTypeID( "Cmnd" )
Call ref20.PutIndex( idCmnd, 18 )
DIM idActn
idActn = objApp.CharIDToTypeID( "Actn" )
Call ref20.PutName( idActn, "Moneta_AUKCJA" )
DIM idASet
idASet = objApp.CharIDToTypeID( "ASet" )
Call ref20.PutName( idASet, "TrimAndAdd" )
Call desc21.PutReference( idnull, ref20 )
Call objApp.ExecuteAction( idPly, desc21, dialogMode )
PS. Maybe a
codeoption in forum could be added for script block?