Skip navigation
apmaui808
Currently Being Moderated

Adding A Text Layer Using Creation Date or Prompted Date

May 24, 2012 8:30 PM

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","S eptember","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!

 
Replies
  • JJMack
    5,979 posts
    Jan 9, 2006
    Currently Being Moderated
    May 24, 2012 9:54 PM   in reply to apmaui808

    I don't know javascript but you may want this

     

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

    alert("exifInfo = " + exifInfo); 

    if (exifInfo=="") {

     

     

     

     

     

     

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

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

    mytextRef.contents = phoTime

     
    |
    Mark as:
  • JJMack
    5,979 posts
    Jan 9, 2006
    Currently Being Moderated
    May 25, 2012 6:44 PM   in reply to apmaui808

    No you had if (exifInfo = "") { should be if (exifInfo == "") { and using var exifInfo = docRef.info.exif.toString();  would not trigger if (exifInfo == "") { so you would not be prompted for a date the alert should have shown you that and the else exif routine would not find an exif date so photoTime would go defined when there was no EXIF data,

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points