3 Replies Latest reply: May 25, 2012 6:44 PM by JJMack RSS

    Adding A Text Layer Using Creation Date or Prompted Date

    apmaui808

      I want to add a text layer for the date. My problem is if the file has EXIF info, the script below works, but if the image does not have EXIF info (e.g., the Sunset sample in Windows), it will not prompt for the date so I can type the date I like. What am I doing wrong here?

       

      Here is the sample script. Open an image and run the script:

       

      var originalUnit = preferences.rulerUnits

      preferences.rulerUnits = Units.PERCENT

      displayDialogs = DialogModes.NO

       

      var docRef=activeDocument;

      var exifInfo = docRef.info.exif.toString();

       

      if (exifInfo ="") {

      var phoTime = prompt('Type the PICTURE DAY according to the following format: mm/dd/yyyy  ', '01/01/2012'); 

      }

       

      else {

      var numExifItems = docRef.info.exif.length;

      for (var i = 0; i < docRef.info.exif.length; i++){

      exifInfo = exifInfo + docRef.info.exif[i][0] + " = " + docRef.info.exif[i][1] + "\r";

       

      key=docRef.info.exif[i][0];

      keyData=docRef.info.exif[i][1];

       

      if (key == "Date Time Original") {

      var phoTime = keyData;

      var dateArray1 = phoTime.split(" ", 2);

      phoTime = dateArray1[0];

      phoHour = dateArray1[1];

      var dateArray2 = phoTime.split(":");

      var monthsArray = ["January","February","March","April","May","June","July","August","September","October", "November","December"];

      phoTime = monthsArray[dateArray2[1]-1]+" " + dateArray2[2]+ ", " + dateArray2[0];

      var picYr = dateArray2[0];

               }

           }

      }

       

      var textRef = docRef.artLayers.add();

      textRef.kind = LayerKind.TEXT;

      textRef.name = "Photo Date";

      var mytextRef = textRef.textItem;

       

      mytextRef.size = 14;

      mytextRef.font = "Arial";

             

      var newColor = new SolidColor();

      newColor.rgb.red = 0;

      newColor.rgb.green = 0;

      newColor.rgb.blue = 0;

      mytextRef.color = newColor;

         

      mytextRef.position = new Array(50, 40);

      mytextRef.justification = Justification.CENTER

       

      textRef.blendMode = BlendMode.NORMAL;

      textRef.opacity = 100;

         

      // populate the text layer based on the file's date or whatever was typed during the prompt

      mytextRef.contents = phoTime

       

      Thanks!