@JSXBIN@ES@2.0@MyBbyBnAIMVbyBn0AHJWn
Conveniently, especially if you need to write a script for Photoshop to order and do not want to give the source. As for the possibility of its decompiling, I did not understand it in detail, but I think that it changes the variables and does some optimization after all.#target photoshop
This is plain javascript with Adobe libraries.app.activeDocument.width. as ( "px" );
Because ExtendScript is cross-platform, file paths are represented as / d / Temp / ...#target photoshop
app.bringToFront(); // Photoshop. , , .
var Constants = { /* - */ }
ProcessDir(Constants.InputDir, Constants.OutputDir);
function ProcessDir(dir, outDir) {
var folder = Folder(dir); // Adobe-
var files = folder.getFiles(Constants.FileMask); // , (*.jpg,*.png) .
var outFolder = Folder(outDir);
if (!outFolder.exists) {
if (!outFolder.create()) {
alert( "Cannot create output folder" );
return ; //
}
}
var totalFiles = 0;
for ( var fileNum in files) {
var outFile = GetOutputFileName(files[fileNum], outFolder.fullName); //
AddLogoToFile(files[fileNum], outFile); // ,
totalFiles++;
}
alert(totalFiles + " files processed" ); // Photoshop-
}
function AddLogoToFile(file, outputFile) {
var photoFile = File(file); // , open
var logoFile = File(Constants.AddLogo.LogoPath);
app.open(logoFile); //
app.activeDocument.artLayers[ "Text" ].copy(); // ArtLayers – . "Text"
var logoWidth = app.activeDocument.width. as ( "px" );
var logoHeight = app.activeDocument.height. as ( "px" );
app.activeDocument.close();
app.open(photoFile); //
var width = app.activeDocument.width. as ( "px" );
var height = app.activeDocument.height. as ( "px" );
var logoLayer = app.activeDocument.artLayers.add(); // ,
logoLayer.name = "Logo" ; //
app.activeDocument.paste(); // clipboard
var shape = [ // Photoshop ; ,
[(width - logoWidth) / 2, (height - logoHeight) / 2],
[(width - logoWidth) / 2, (height + logoHeight) / 2],
[(width + logoWidth) / 2, (height + logoHeight) / 2],
[(width + logoWidth) / 2, (height - logoHeight) / 2]
];
app.activeDocument.selection.select(shape);
app.activeDocument.selection.translate( // selection
new UnitValue((width - logoWidth)/ 2, "px" ),
new UnitValue((height - logoHeight) / 2, "px" ));
var minImageDimension = Math.min(width, height); // , 5
var logoScaleMultiplier = minImageDimension / 5 / logoWidth * 100;
app.activeDocument.selection.resize(logoScaleMultiplier, logoScaleMultiplier, AnchorPosition.BOTTOMRIGHT); //
app.activeDocument.selection.deselect();
app.activeDocument.artLayers[ "Logo" ].opacity = 75; //
app.activeDocument.artLayers[ "Logo" ].blendMode = BlendMode.LUMINOSITY; // ,
// blending options! .
SaveFile(outputFile); //
}
function SaveFile(outputFile) {
var isPng = /png$/i.test(outputFile);
var saveOptions;
if (isPng) {
saveOptions = new PNGSaveOptions();
} else {
saveOptions = new JPEGSaveOptions(); /* */
}
app.activeDocument.saveAs(File(outputFile), saveOptions, true , Extension.LOWERCASE)
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); //
}
The script is ready. It remains to make a logo in PSD format - such that the Text layer is inside, on which the logo should be placed.var idsetd = charIDToTypeID( "setd" );
var desc15 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idLefx = charIDToTypeID( "Lefx" );
ref6.putProperty( idPrpr, idLefx );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref6.putEnumerated( idLyr, idOrdn, idTrgt );
desc15.putReference( idnull, ref6 );
var idT = charIDToTypeID( "T " );
var desc16 = new ActionDescriptor();
var idScl = charIDToTypeID( "Scl " );
var idPrc = charIDToTypeID( "#Prc" );
desc16.putUnitDouble( idScl, idPrc, 100.000000 );
var idDrSh = charIDToTypeID( "DrSh" );
var desc17 = new ActionDescriptor();
var idenab = charIDToTypeID( "enab" );
desc17.putBoolean( idenab, true );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idMltp = charIDToTypeID( "Mltp" );
desc17.putEnumerated( idMd, idBlnM, idMltp );
var idClr = charIDToTypeID( "Clr " );
var desc18 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc18.putDouble( idRd, 0.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc18.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc18.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc17.putObject( idClr, idRGBC, desc18 );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc17.putUnitDouble( idOpct, idPrc, 75.000000 );
var iduglg = charIDToTypeID( "uglg" );
desc17.putBoolean( iduglg, true );
var idlagl = charIDToTypeID( "lagl" );
var idAng = charIDToTypeID( "#Ang" );
desc17.putUnitDouble( idlagl, idAng, 120.000000 );
var idDstn = charIDToTypeID( "Dstn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc17.putUnitDouble( idDstn, idPxl, 5.000000 );
var idCkmt = charIDToTypeID( "Ckmt" );
var idPxl = charIDToTypeID( "#Pxl" );
desc17.putUnitDouble( idCkmt, idPxl, 0.000000 );
var idblur = charIDToTypeID( "blur" );
var idPxl = charIDToTypeID( "#Pxl" );
desc17.putUnitDouble( idblur, idPxl, 5.000000 );
var idNose = charIDToTypeID( "Nose" );
var idPrc = charIDToTypeID( "#Prc" );
desc17.putUnitDouble( idNose, idPrc, 0.000000 );
var idAntA = charIDToTypeID( "AntA" );
desc17.putBoolean( idAntA, false );
var idTrnS = charIDToTypeID( "TrnS" );
var desc19 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc19.putString( idNm, "Linear" );
var idShpC = charIDToTypeID( "ShpC" );
desc17.putObject( idTrnS, idShpC, desc19 );
var idlayerConceals = stringIDToTypeID( "layerConceals" );
desc17.putBoolean( idlayerConceals, true );
var idDrSh = charIDToTypeID( "DrSh" );
desc16.putObject( idDrSh, idDrSh, desc17 );
var idLefx = charIDToTypeID( "Lefx" );
desc15.putObject( idT, idLefx, desc16 );
executeAction( idsetd, desc15, DialogModes.NO );
What do you think this code does? It adds a shadow (Drop Shadow) to the layer, this can be seen by the name “DrSh”. I suspect that inside Photoshop, this is what the controls in GUI are called right.Source: https://habr.com/ru/post/112907/
All Articles