- 
// Pour être sur que la fenêtre de photoshop soit active
 
- 
#target photoshop
 
- 
app.bringToFront();
 
- 
 
- 
// A décommenter si l’on veut déboger le script
 
- 
/*
 
- 
debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
 
- 
$.level = 0;
 
- 
debugger; // launch debugger on next line
 
- 
*/
 
- 
 
- 
// Pas de question pendant le script
 
- 
displayDialogs = DialogModes.NO;
 
- 
 
- 
// On sauvegarde et met en place les unités de mesure
 
- 
var defaultRulerUnits = preferences.rulerUnits;
 
- 
preferences.rulerUnits = Units.PIXELS;
 
- 
var defaultTypeUnits = preferences.typeUnits;
 
- 
preferences.typeUnits = TypeUnits.PIXELS;
 
- 
 
- 
// Quelques variables fort utiles pour la suite
 
- 
 
- 
var AD = activeDocument;
 
- 
 
- 
var black = new SolidColor();
 
- 
black.rgb.red = black.rgb.green = black.rgb.blue = 0;
 
- 
var white = new SolidColor();
 
- 
white.rgb.red = white.rgb.green = white.rgb.blue = 255;
 
- 
 
- 
backgroundColor = black;
 
- 
 
- 
var header =  » 133434 « ;
 
- 
 
- 
// Nous allons chercher les infos qui nous interessent dans la liste des infos EXIF
 
- 
 
- 
for(n = 0; n < AD.info.exif.length; n = n + 1 ) {
 
- 
        var stringTemp = AD.info.exif[n][1];
 
- 
 
- 
        // J’ai trouvé ces références à coup d’essais, le nom de variable devraient être
 
- 
        // en toutes lettres, probablement un problème de traduction.
 
- 
 
- 
        // Durée d’exposition
 
- 
        if(stringTemp.indexOf( » 133434″)!=-1){
 
- 
                var expTime = stringTemp.substr(header.length,stringTemp.length-header.length);
 
- 
        }
 
- 
 
- 
  // Date de prise de vue
 
- 
        if(stringTemp.indexOf( » 136867″)!=-1){
 
- 
                var phoTime = stringTemp.substr(header.length,stringTemp.length-header.length);
 
- 
                var dateArray1 = phoTime.split( » « , 1);
 
- 
                phoTime = dateArray1[0];
 
- 
                var dateArray2 = phoTime.split(« : »);
 
- 
 
- 
                var monthsArray =[« Janvier », « Février », « Mars », « Avril », « Mai », « Juin », « Juillet », « Août », « Septembre », « Octobre », « Novembre », « Décembre »];
 
- 
                phoTime = dateArray2[2] + » « + monthsArray[dateArray2[1]-1]+ » « +dateArray2[0];
 
- 
        }
 
- 
 
- 
  // Modèle d’appareil photo
 
- 
        if(stringTemp.indexOf( » 100272″)!=-1){
 
- 
                var cameraModel = stringTemp.substr(header.length,stringTemp.length-header.length);
 
- 
        }
 
- 
 
- 
  // Ouverture focale
 
- 
        if(stringTemp.indexOf( » 133437″)!=-1){
 
- 
                var FStop = stringTemp.substr(header.length,stringTemp.length-header.length);
 
- 
        }
 
- 
 
- 
  // Règlage ISO
 
- 
        if(stringTemp.indexOf( » 134855″)!=-1){
 
- 
                var ISO = stringTemp.substr(header.length,stringTemp.length-header.length);
 
- 
        }
 
- 
 
- 
        // Longueur focale
 
- 
        if(stringTemp.indexOf( » 137386″)!=-1){
 
- 
                var FLength = stringTemp.substr(header.length,stringTemp.length-header.length);
 
- 
        }
 
- 
}
 
- 
 
- 
var dlgResource = «  »;
 
- 
    dlgResource += « dialog{text:’Paramètres Watermark Exif’,bounds:[100,100,440,320], « 
 
- 
        dlgResource +=  » panel1:Panel{bounds:[20,20,110,105] , text:’Position’ ,\
 
- 
                         properties:{borderStyle:’etched’,su1PanelCoordinates:true}, « ;
 
- 
        dlgResource +=  »  group0:Group{bounds:[0,10,100,100], « 
 
- 
        dlgResource +=  »   radiobutton1:RadioButton{bounds:[10,10,41,31] , text:’1′ }, « 
 
- 
        dlgResource +=  »   radiobutton2:RadioButton{bounds:[50,10,81,31] , text:’2′ }, « 
 
- 
        dlgResource +=  »   radiobutton3:RadioButton{bounds:[10,35,41,71] , text:’3′ }, « 
 
- 
        dlgResource +=  »   radiobutton4:RadioButton{bounds:[50,35,81,71] , text:’4′, value:true} « 
 
- 
        dlgResource +=  »  } « 
 
- 
        dlgResource +=  » }, « 
 
- 
        dlgResource +=  » copyrightInfoSt: StaticText { text:’Copyright Info:’, bounds:[130,20,320,40] }, « 
 
- 
        dlgResource +=  » copyrightInfoEt: EditText { text:’copyright’, bounds:[130, 42, 320, 62] }, « 
 
- 
        dlgResource +=  » FlattenCb:     Checkbox { text:’Applatir les couches’, bounds:[130,75,320,95], value:false }, « 
 
- 
        dlgResource +=  » FontDDLSt: StaticText { text:’Police de caractère:’, bounds:[130,110,320,130] }, « 
 
- 
        dlgResource +=  » FontDDL: DropDownList { bounds:[130,132,320,152] }, « 
 
- 
        dlgResource +=  » FontSizeSt: StaticText { text:’Taille de texte:’, bounds:[20,110,120,130] }, « 
 
- 
        dlgResource +=  » FontSizeDDL: DropDownList { bounds:[20,132,120,152] }, « 
 
- 
        dlgResource +=  » okBtn:Button{bounds:[120,180,210,200] , text:’OK’ }, « 
 
- 
        dlgResource +=  » cancelBtn:Button{bounds:[230,180,320,200] , text:’Annuler’ } « 
 
- 
        dlgResource += « } »;
 
- 
 
- 
var dlgPos = new Window(dlgResource);
 
- 
var SelFont = 0
 
- 
for ( var i = 0; i < fonts.length; i++ ) {
 
- 
        dlgPos.FontDDL.add( « item », fonts[i].name );
 
- 
        if (fonts[i].name == ‘Verdana’) {
 
- 
          SelFont = i;
 
- 
        }
 
- 
}
 
- 
dlgPos.FontDDL.items[SelFont].selected = true;
 
- 
for ( var i = 3; i < 20; i++ ) {
 
- 
        dlgPos.FontSizeDDL.add( « item », i );
 
- 
}
 
- 
dlgPos.FontSizeDDL.items[3].selected = true;
 
- 
 
- 
//dlgPos.panel1.group0.radiobutton1.value = true;
 
- 
 
- 
dlgPos.okBtn.onClick = function () { dlgPos.close(1); };
 
- 
dlgPos.cancelBtn.onClick = function () { dlgPos.close(2); };
 
- 
 
- 
if (dlgPos.show() == 1){
 
- 
  var WtPosS = 4;
 
- 
  if (dlgPos.panel1.group0.radiobutton1.value == true){
 
- 
    WtPosS = 1;
 
- 
  }
 
- 
  if (dlgPos.panel1.group0.radiobutton2.value == true){
 
- 
    WtPosS = 2;
 
- 
  }
 
- 
  if (dlgPos.panel1.group0.radiobutton3.value == true){
 
- 
    WtPosS = 3;
 
- 
  }
 
- 
  if (dlgPos.panel1.group0.radiobutton4.value == true){
 
- 
    WtPosS = 4;
 
- 
  }
 
- 
  var CpyInfoTxt = dlgPos.copyrightInfoEt.text;
 
- 
  var FlattenLC = dlgPos.FlattenCb.value;
 
- 
  var SelFontName = dlgPos.FontDDL.selection;
 
- 
  var SelTxtSize = dlgPos.FontSizeDDL.selection.text;
 
- 
  Watermarkize(WtPosS, CpyInfoTxt, FlattenLC, SelFontName, SelTxtSize);
 
- 
}else{
 
- 
  //alert(« pas blu ! »);
 
- 
}
 
- 
 
- 
function Watermarkize (WtPos, CopyTx, FlattenLy, TextFnt, TxtSize) {
 
- 
    var Off7 = 7;    // Distance entre le texte et le cadre
 
- 
    var Undent = 6;  // Distance entre le cadre et le bord de la photo
 
- 
 
- 
    // On crée un nouveau calque texte
 
- 
    var infoLayer = AD.artLayers.add();
 
- 
    infoLayer.kind = LayerKind.TEXT;
 
- 
    infoLayer.name = « Exif WM – Texte »
 
- 
    var TI = infoLayer.textItem;
 
- 
    TI.font = TextFnt;
 
- 
    TI.size = TxtSize;
 
- 
    TI.color = white;
 
- 
 
- 
    // Voici le texte, « \u000D » représente un retour chariot ( caractère n°13, D en hexadécimal)
 
- 
    TI.contents = cameraModel
 
- 
    TI.contents = TI.contents + « \u000D » + FLength +  »  «  + expTime +  »  «  + FStop +  »  «  + ISO +  » ISO »;
 
- 
    TI.contents = TI.contents + « \u000D » + « © « + phoTime + » « + CopyTx ;
 
- 
 
- 
    TI.kind = TextType.PARAGRAPHTEXT;
 
- 
    TI.nobreak = true;
 
- 
 
- 
    // On récupère la taille du texte
 
- 
    var TextWidth  = (infoLayer.bounds[2]-infoLayer.bounds[0]);
 
- 
    var TextHeight = (infoLayer.bounds[3]-infoLayer.bounds[1]);
 
- 
    var TextLeft = AD.width–(TextWidth + Off7 * 2 + Undent);
 
- 
    var TextTop = AD.height–(TextHeight + Off7 * 2 + Undent);
 
- 
 
- 
    if (WtPos == 1) {
 
- 
      TextLeft = (Off7 * 2 + Undent);
 
- 
      TextTop  = (Off7 * 2 + Undent);
 
- 
    };
 
- 
    if (WtPos == 2) {
 
- 
      TextLeft = AD.width–(TextWidth + Off7 * 2 + Undent);
 
- 
      TextTop  = (Off7 * 2 + Undent);
 
- 
    };
 
- 
    if (WtPos == 3) {
 
- 
      TextLeft = (Off7 * 2 + Undent);
 
- 
      TextTop  = AD.height–(TextHeight + Off7 * 2 + Undent);
 
- 
    };
 
- 
 
- 
    // Et on le déplace en bas à gauche, position calculée avec les distances mises en place plus haut
 
- 
    TI.position = [TextLeft,TextTop];
 
- 
 
- 
 
- 
    // On crée un nouveau calque, pour y dessiner notre cadre
 
- 
    var CadreLayer = AD.artLayers.add();
 
- 
    CadreLayer.name = « Exif WM – Cadre »;
 
- 
    var CadreRight = TextLeft + TextWidth + Off7;
 
- 
    var CadreBottom = TextTop + TextHeight + Off7;
 
- 
 
- 
    // cadre dont la taille et la position sont calculées selon celles du texte
 
- 
    var selectionBounds = [[TextLeft-Off7,TextTop-Off7], [CadreRight,TextTop-Off7], [CadreRight,CadreBottom], [TextLeft-Off7,CadreBottom]];
 
- 
 
- 
    // On crée une sélection
 
- 
    AD.selection.select(selectionBounds,SelectionType.REPLACE,0,false);
 
- 
    // On la remplis d’un aplat de noir visible à 35% ( transparent à 65% donc )
 
- 
    AD.selection.fill(black,ColorBlendMode.VIVIDLIGHT,35);
 
- 
    // Puis on trace le contour blanc visible à 100%
 
- 
    AD.selection.stroke(white,3,StrokeLocation.OUTSIDE, ColorBlendMode.VIVIDLIGHT, 100, false);
 
- 
    AD.selection.deselect();
 
- 
 
- 
    // On place le texte au dessus du cadre ( pour qu’il ne soit pas affecté par l’aplat noir )
 
- 
    infoLayer.move(CadreLayer,ElementPlacement.PLACEBEFORE);
 
- 
    // On lie les deux calques ( ils bougeront ensemble )
 
- 
    CadreLayer.link(infoLayer);
 
- 
 
- 
    if (FlattenLy) {
 
- 
      AD.flatten();
 
- 
    }
 
- 
}
 
- 
 
- 
// on remet en place les unités de mesure sauvegardées
 
- 
preferences.rulerUnits = defaultRulerUnits;
 
- 
preferences.typeUnits = defaultTypeUnits;