Adobe Photoshop

It is often desirable to add a visible watermark to a document image. This following script takes the test file (TIFF), adds a large copyright symbol as a watermark, applies a style (Watermark emboss A) created for the ADIEUX Project, flattens the image and saves the resulting file in the PNG format:

// =======================================================
var idOpn = charIDToTypeID( "Opn " );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc1.putPath( idnull, new File( "D:\\adieux\\archive\\tiff\\adieux-ocr-testfile-1.tif" ) );
executeAction( idOpn, desc1, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idcustomShapeTool = stringIDToTypeID( "customShapeTool" );
ref1.putClass( idcustomShapeTool );
desc2.putReference( idnull, ref1 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc2.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc2.putBoolean( idforceNotify, true );
executeAction( idslct, desc2, DialogModes.NO );

// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref2.putClass( idcontentLayer );
desc3.putReference( idnull, ref2 );
var idUsng = charIDToTypeID( "Usng" );
var desc4 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc4.putClass( idType, idsolidColorLayer );
var idShp = charIDToTypeID( "Shp " );
var desc5 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc5.putString( idNm, "Copyright symbol" );
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idTop, idPxl, 380.524345 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idLeft, idPxl, 806.267030 );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idBtom, idPxl, 1121.761576 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idRght, idPxl, 1531.607629 );
var idcustomShape = stringIDToTypeID( "customShape" );
desc4.putObject( idShp, idcustomShape, desc5 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc3.putObject( idUsng, idcontentLayer, desc4 );
executeAction( idMk, desc3, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc6 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idmoveTool = stringIDToTypeID( "moveTool" );
ref3.putClass( idmoveTool );
desc6.putReference( idnull, ref3 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc6.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc6.putBoolean( idforceNotify, true );
executeAction( idslct, desc6, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc7 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref4 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref4.putProperty( idChnl, idfsel );
desc7.putReference( idnull, ref4 );
var idT = charIDToTypeID( "T " );
var idOrdn = charIDToTypeID( "Ordn" );
var idAl = charIDToTypeID( "Al " );
desc7.putEnumerated( idT, idOrdn, idAl );
executeAction( idsetd, desc7, DialogModes.NO );

// =======================================================
var idAlgn = charIDToTypeID( "Algn" );
var desc8 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref5.putEnumerated( idLyr, idOrdn, idTrgt );
desc8.putReference( idnull, ref5 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCV = charIDToTypeID( "AdCV" );
desc8.putEnumerated( idUsng, idADSt, idAdCV );
executeAction( idAlgn, desc8, DialogModes.NO );

// =======================================================
var idAlgn = charIDToTypeID( "Algn" );
var desc9 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref6.putEnumerated( idLyr, idOrdn, idTrgt );
desc9.putReference( idnull, ref6 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCH = charIDToTypeID( "AdCH" );
desc9.putEnumerated( idUsng, idADSt, idAdCH );
executeAction( idAlgn, desc9, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref7 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref7.putProperty( idChnl, idfsel );
desc10.putReference( idnull, ref7 );
var idT = charIDToTypeID( "T " );
var idOrdn = charIDToTypeID( "Ordn" );
var idNone = charIDToTypeID( "None" );
desc10.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetd, desc10, DialogModes.NO );

// =======================================================
var idASty = charIDToTypeID( "ASty" );
var desc11 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idStyl = charIDToTypeID( "Styl" );
ref8.putName( idStyl, "Watermark emboss A" );
desc11.putReference( idnull, ref8 );
var idT = charIDToTypeID( "T " );
var ref9 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref9.putEnumerated( idLyr, idOrdn, idTrgt );
desc11.putReference( idT, ref9 );
executeAction( idASty, desc11, DialogModes.NO );

// =======================================================
var idFltI = charIDToTypeID( "FltI" );
executeAction( idFltI, undefined, DialogModes.NO );

// =======================================================
var idsave = charIDToTypeID( "save" );
var desc12 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc13 = new ActionDescriptor();
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc13.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc13.putEnumerated( idPNGf, idPNGf, idPGAd );
var idPNGF = charIDToTypeID( "PNGF" );
desc12.putObject( idAs, idPNGF, desc13 );
var idIn = charIDToTypeID( "In " );
desc12.putPath( idIn, new File( "D:\\adieux\\archive\\tiff" ) );
executeAction( idsave, desc12, DialogModes.NO );

// =======================================================
var idCls = charIDToTypeID( "Cls " );
executeAction( idCls, undefined, DialogModes.NO );

This script would necessarily have to be revised depending on the dimensions of the source images used (the copyright symbol is centered but its dimensions are here chosen to suit a 2200x1600 test file). For reference, the resulting watermarked PNG file (6.65MB) is here.

Note that automation of watermarkering suggest the possibility of creating a script that would reverse the process to remove watermarks; however, in this case that would not be possible as there is an external dependendency: a style (Watermark emboss A).

Continued Continued