// Photo Exif // (c) 2020 Steve Banham scriptName = "Photo Exif"; scriptVersion = "1.3"; scriptDate = "11/4/2020"; scriptCopyright = "(c) 2020 Steve Banham"; scriptMinVersion = "12.19"; scriptDesc = "Adds a command to show photo exif metadata."; var strName, strCopyright, strDescription, intAltitude, intLatitude, intLongitude, temporaryFolder = 2, tempImage, tempFolder; function OnInit(initData) { initData.name = scriptName; initData.version = scriptVersion; initData.copyright = scriptCopyright; initData.desc = scriptDesc; initData.default_enable = true; initData.min_version = scriptMinVersion; initData.config_desc = DOpus.Create.Map(); var configName = ""; configName = "DPI"; initData.Config[configName] = "200"; initData.config_desc(configName) = "Set the DPI used to calculate the maximum print size."; configName = "Inches"; initData.Config[configName] = false; initData.config_desc(configName) = "Display maximum print size in inches." configName = "Selection Update"; initData.Config[configName] = true; initData.config_desc(configName) = "Monitor for and update the dialog when another image file is selected."; configName = "Rotate Image"; initData.Config[configName] = false; initData.config_desc(configName) = "Use image rotation metadata in the photo preview (Slows display down)."; var cmd = initData.AddCommand(); cmd.name = "PhotoExif"; cmd.method = "onPhotoExif"; cmd.desc = "Adds a command to show photo exif metadata."; cmd.label = "PhotoExif"; } function onPhotoExif(scriptCmdData) { var srcTab = scriptCmdData.func.sourcetab; var argDpi = Script.Config["DPI"]; var argInches = Script.Config["Inches"]; var strUnits = "cm"; flgNameChanged = false; flgCopyrightChanged = false; flgDescriptionChanged = false; if (argInches == true){ strUnits = "\""; } if (srcTab.stats.selfiles == 0) { DOpus.Output("No files selected."); return; } if (srcTab.selected_files(0).metadata != "image") { DOpus.Output("Not an image file."); return; } else { var dlg = DOpus.Dlg; dlg.window = srcTab; dlg.title = scriptName + " " + scriptVersion + " - Directory Opus"; dlg.template = "dlgPictureInfo"; dlg.LoadPosition("Steve_PhotoExif"); dlg.detach = true; dlg.Show(); dlg.Control("staticNotify").style = "b"; if (Script.Config["Selection Update"] == true) { dlg.SetTimer(100, "timer"); } } updateDialog(srcTab, scriptCmdData, dlg, argDpi, argInches, strUnits); while (true) { var msg = dlg.GetMsg(); if (!msg.result) break; if (msg.event == "timer" && Script.Config["Selection Update"] == true) { srcTab.Update(); if (srcTab.source == true) { if (srcTab.stats.selitems != 0 && srcTab.source == true) { if (srcTab.selected(0).is_dir == true) { dlg.Control("staticNotify").label = "You have selected a folder."; updateNotImage(srcTab, dlg); } else { if (srcTab.selected_files(0).metadata == "image" && strName != srcTab.selected_files(0).name) { updateDialog(srcTab, scriptCmdData, dlg, argDpi, argInches, strUnits); dlg.Control("staticNotify").label = ""; } if (srcTab.selected_files(0).metadata != "image" && strName != srcTab.selected_files(0).name) { dlg.Control("staticNotify").label = "Selected file is not an image."; updateNotImage(srcTab, dlg); } } } } else { dlg.Control("staticNotify").label = "Source lister closed"; dlg.Control("btnShow").enabled = false; dlg.Control("btnApply").enabled = false; dlg.Control("editName").enabled = false; dlg.Control("editPath").enabled = false; dlg.Control("btnGoogleMaps").enabled = false; dlg.Control("editCopyright").enabled = false; dlg.Control("editDescription").enabled = false; } } if (msg.event == "click" && dlg.Control("btnGoogleMaps").focus == true){ var strCommand = "https://www.google.com/maps?q=" + dlg.Control("editLatitude").value + "," + dlg.Control("editLongitude").value; scriptCmdData.func.command.RunCommand(strCommand); } if (msg.event == "editchange" && dlg.Control("editName").focus == true) { if (dlg.Control("editName").value != strName) { flgNameChanged = true; dlg.Control("staticNotify").label = ""; } else { flgNameChanged = false; dlg.Control("staticNotify").label = ""; } } if (msg.event == "editchange" && dlg.Control("editCopyright").focus == true) { if (dlg.Control("editCopyright").value != strCopyright) { flgCopyrightChanged = true; strCopyright = dlg.Control("editCopyright").value; dlg.Control("staticNotify").label = ""; } else { flgCopyrightChanged = false; dlg.Control("staticNotify").label = ""; } } if (msg.event == "editchange" && dlg.Control("editDescription").focus == true) { if (dlg.Control("editDescription").value != strDescription) { flgDescriptionChanged = true; strDescription = dlg.Control("editDescription").value; dlg.Control("staticNotify").label = ""; } else { flgDescriptionChanged = false; dlg.Control("staticNotify").label = ""; } } if (flgCopyrightChanged == true || flgDescriptionChanged == true || flgNameChanged == true) { dlg.Control("btnApply").enabled = true; } else { dlg.Control("btnApply").enabled = false; } if (msg.event == "click" && dlg.Control("btnApply").focus == true){ if (!DOpus.FSUtil.Exists(srcTab.selected_files(0).path + "\\" + strName)) { dlg.Request("File no longer exists!", "Ok", "File no longer exists!"); return } if (flgNameChanged == true) { var strCommand = "Rename FROM " + srcTab.selected_files(0).path + "\\" + strName + " TO \"" + srcTab.selected_files(0).path + "\\" + dlg.Control("editName").value + "\""; scriptCmdData.func.command.RunCommand(strCommand); strName = dlg.Control("editName").value; flgNameChanged = false; } if (flgCopyrightChanged == true) { var strCommand = "SetAttr FILE=\"" + srcTab.selected_files(0).path + "\\" + dlg.Control("editName").value + "\"" + " META \"copyright:" + dlg.Control("editCopyright").value + "\""; scriptCmdData.func.command.RunCommand(strCommand); flgCopyrightChanged = false; } if (flgDescriptionChanged == true) { var strCommand = "SetAttr FILE=\"" + srcTab.selected_files(0).path + "\\" + dlg.Control("editName").value + "\"" + " META \"imagedesc:" + dlg.Control("editDescription").value + "\""; scriptCmdData.func.command.RunCommand(strCommand); flgDescriptionChanged = false; } dlg.Control("btnApply").enabled = false; dlg.Control("staticNotify").label = "File updated."; } if (msg.event == "click" && dlg.Control("btnShow").focus == true){ var strCommand = "Show " + srcTab.selected_files(0).path + "\\" + strName; scriptCmdData.func.command.RunCommand(strCommand); } } dlg.SavePosition("Steve_PhotoExif"); } function updateNotImage(srcTab, dlg) { if (srcTab.selected(0).is_dir == true) { dlg.Control("editName").value = srcTab.selected(0).name; dlg.Control("editPath").value = srcTab.selected(0).path; strName = dlg.Control("editName").value; } else { dlg.Control("editName").value = srcTab.selected_files(0).name; dlg.Control("editPath").value = srcTab.selected_files(0).path; strName = dlg.Control("editName").value; } strName = dlg.Control("staticImage").label = ""; dlg.Control("editName").enabled = false; dlg.Control("editPath").enabled = false; dlg.Control("editCopyright").value = ""; dlg.Control("editCopyright").enabled = false; dlg.Control("editDescription").value = ""; dlg.Control("editDescription").enabled = false; dlg.Control("editCameraMake").value = ""; dlg.Control("editCameraModel").value = ""; dlg.Control("editExposure").value = ""; dlg.Control("editISO").value = ""; dlg.Control("editFocalLength").value = ""; dlg.Control("editFStop").value = ""; dlg.Control("editFlash").value = ""; dlg.Control("editDateTaken").value = ""; dlg.Control("editWidth").value = ""; dlg.Control("editHeight").value = ""; dlg.Control("editBitDepth").value = ""; dlg.Control("editPrintSize").value = ""; dlg.Control("editAltitude").value = ""; dlg.Control("editLatitude").value = ""; dlg.Control("editLongitude").value = ""; dlg.Control("btnGoogleMaps").enabled = false; dlg.Control("btnApply").visible = false; } function updateDialog(srcTab, scriptCmdData, dlg, argDpi, argInches, strUnits) { if (Script.Config["Rotate Image"] == true && srcTab.selected_files(0).metadata.image.rotation > 0) { dlg.Control("staticImage").label = ""; } else { dlg.Control("staticImage").label = srcTab.selected_files(0).path + "\\" + srcTab.selected_files(0).name; } dlg.Control("btnApply").visible = true; strName = srcTab.selected_files(0).name; dlg.Control("editName").value = strName; dlg.Control("editName").enabled = true; dlg.Control("editPath").value = srcTab.selected_files(0).path; dlg.Control("editPath").enabled = true; strCopyright = srcTab.selected_files(0).metadata.image.copyright; if (!strCopyright) strCopyright = ""; dlg.Control("editCopyright").value = strCopyright; dlg.Control("editCopyright").enabled = true; strDescription = srcTab.selected_files(0).metadata.image.imagedesc; if (!strDescription) strDescription = ""; dlg.Control("editDescription").value = strDescription; dlg.Control("editDescription").enabled = true; dlg.Control("editCameraMake").value = srcTab.selected_files(0).metadata.image.cameramake; dlg.Control("editCameraModel").value = srcTab.selected_files(0).metadata.image.cameramodel; if (srcTab.selected_files(0).metadata.image.exposuretime) { expTime = 1 / srcTab.selected_files(0).metadata.image.exposuretime; expTime = "1/" + expTime + " secs"; } else var expTime = ""; dlg.Control("editExposure").value = expTime; dlg.Control("editISO").value = srcTab.selected_files(0).metadata.image.isorating; if (srcTab.selected_files(0).metadata.image.focallength) { var focLength = srcTab.selected_files(0).metadata.image.focallength + " mm"; } else var focLength = "" dlg.Control("editFocalLength").value = focLength; if (srcTab.selected_files(0).metadata.image.fnumber) { var fStop = "f/" + srcTab.selected_files(0).metadata.image.fnumber; } else fStop = ""; dlg.Control("editFStop").value = fStop; dlg.Control("editFlash").value = srcTab.selected_files(0).metadata.image.flash; dlg.Control("editDateTaken").value = srcTab.selected_files(0).metadata.image.datetaken; dlg.Control("editWidth").value = srcTab.selected_files(0).metadata.image.picwidth; dlg.Control("editHeight").value = srcTab.selected_files(0).metadata.image.picheight; dlg.Control("editBitDepth").value = srcTab.selected_files(0).metadata.image.picdepth; dlg.Control("staticPrintSize").label = "Maximum Print Size @ " + argDpi + "dpi"; var prtMaxWidth = srcTab.selected_files(0).metadata.image.picwidth / argDpi; var prtMaxHeight = srcTab.selected_files(0).metadata.image.picheight / argDpi; if (strUnits == "cm") { prtMaxWidth = prtMaxWidth * 2.54; prtMaxHeight = prtMaxHeight * 2.54; } prtMaxWidth = prtMaxWidth.toFixed(2); prtMaxHeight = prtMaxHeight.toFixed(2); prtComplete = prtMaxWidth + strUnits + " x " + prtMaxHeight + strUnits; dlg.Control("editPrintSize").value = prtComplete; intAltitude = srcTab.selected_files(0).metadata.image.altitude; intLatitude = srcTab.selected_files(0).metadata.image.latitude; intLongitude = srcTab.selected_files(0).metadata.image.longitude; if (intAltitude) { intAltitude = intAltitude.toFixed(2); intAltitude = intAltitude + " metres"; dlg.Control("editAltitude").value = intAltitude; } if (intLatitude) { dlg.Control("editLatitude").value = intLatitude; var i = 1; } if (intLongitude) { dlg.Control("editLongitude").value = intLongitude; i = i + 1; } if (i == 2) { dlg.Control("btnGoogleMaps").enabled = true; } if (Script.Config["Rotate Image"] == true && srcTab.selected_files(0).metadata.image.rotation > 0) { dlg.Control("staticNotify").label = "Rotating image..."; var intRotation = 360 - srcTab.selected_files(0).metadata.image.rotation; var fso = new ActiveXObject("Scripting.FilesystemObject"); tempFolder = fso.GetSpecialFolder(temporaryFolder); scriptCmdData.func.command.RunCommand("Image FROM=\"" + srcTab.selected_files(0).realpath + "\"" + " ROTATE=" + intRotation + " TO=\"" + tempFolder + "\""); tempImage = tempFolder + "\\" + srcTab.selected_files(0).name; dlg.Control("staticImage").label = tempFolder + "\\" + srcTab.selected_files(0).name; scriptCmdData.func.command.RunCommand("Delete QUIET \"" + tempFolder + "\\" + srcTab.selected_files(0).name + "\""); dlg.Control("staticNotify").label = ""; } return; } function OnAboutScript(aboutData){ dlg = DOpus.Dlg; dlg.window = aboutData.window; dlg.title = scriptName + " " + scriptVersion; dlg.message = scriptName + " v" + scriptVersion + "\t\t\t\t\t" + scriptDate + "\n\n" + scriptDesc + "\n\n" + scriptCopyright; dlg.buttons = "Close"; dlg.icon = "info"; dlg.show; } ==SCRIPT RESOURCES