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!
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
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,
North America
Europe, Middle East and Africa
Asia Pacific