// Photo Exif // (c) 2020 Steve Banham scriptName = "Photo Exif"; scriptVersion = "1.3.3"; scriptDate = "22/4/2020"; scriptCopyright = "(c) 2020 Steve Banham"; scriptMinVersion = "12.20.1"; scriptDesc = "Adds a command to show photo exif metadata."; var strName, strOldTempImage, strCopyright, strDescription, temporaryFolder = 2, tempImage, tempFolder; var intAltitude; var intLatitude; var intLongitude; function OnInit(initData) { initData.name = scriptName; initData.version = scriptVersion; initData.copyright = scriptCopyright; initData.desc = scriptDesc; initData.default_enable = true; initData.min_version = scriptMinVersion; initData.url = "https://resource.dopus.com/t/photo-exif/35015"; initData.config_desc = DOpus.Create.Map(); initData.config_groups = 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."; initData.config_groups(configName) = "Print Size"; configName = "inches"; initData.Config[configName] = false; initData.config_desc(configName) = "Display maximum print size in inches." initData.config_groups(configName) = "Print Size"; configName = "selection_update"; initData.Config[configName] = true; initData.config_desc(configName) = "Monitor for and update the dialog when another image file is selected."; initData.config_groups(configName) = "Options"; configName = "image_rotation"; initData.Config[configName] = true; initData.config_desc(configName) = "Use image rotation metadata in the photo preview."; initData.config_groups(configName) = "Options"; var vecLocation = DOpus.NewVector(); vecLocation.push_back(0); vecLocation.push_back("Google Maps"); vecLocation.push_back("Open Street Map"); vecLocation.push_back("Bing"); configName = "location_service"; initData.config[configName] = vecLocation; initData.config_desc(configName) = "The mapping service used by the Locate button."; initData.config_groups(configName) = "Options"; 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.title = scriptName + " " + scriptVersion + " - Directory Opus"; dlg.template = "dlgPhotoExif"; 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) { scriptCmdData.func.command.RunCommand("Delete NORECYCLE QUIET \"" + tempFolder + "\\" + strOldTempImage + "\""); 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("btnLocate").enabled = false; dlg.Control("editCopyright").enabled = false; dlg.Control("editDescription").enabled = false; } } if (msg.event == "click" && dlg.Control("btnLocate").focus == true){ if (Script.Config["location_service"] == 0) { var strCommand = "https://www.google.com/maps?q=" + intLatitude + "," + intLongitude; } if (Script.Config["location_service"] == 1) { var strCommand = "https://www.openstreetmap.org/?mlat=" + intLatitude + "&mlon=" + intLongitude; } if (Script.Config["location_service"] == 2) { var strCommand = "https://www.bing.com/maps?v=2&q=" + intLatitude + "," + intLongitude; } 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){ scriptCmdData.func.command.RunCommand("Show " + "\"" + dlg.Control("staticImage").label + "\""); } if (msg.event == "click" && dlg.Control("btnLeft").focus == true){ if (srcTab.source == true) { if (!scriptCmdData.func.command.RunCommand("Select PREV")) { scriptCmdData.func.command.RunCommand("Select LAST"); } srcTab.Update(); 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); } } } } } if (msg.event == "click" && dlg.Control("btnRight").focus == true){ if (srcTab.source == true) { if (!scriptCmdData.func.command.RunCommand("Select NEXT")) { scriptCmdData.func.command.RunCommand("Select FIRST"); } srcTab.Update(); 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); } } } } } } 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("staticPath").label = srcTab.selected(0).realpath; strName = dlg.Control("editName").value; } else { dlg.Control("editName").value = srcTab.selected_files(0).name; dlg.Control("staticPath").label = srcTab.selected_files(0).realpath; strName = dlg.Control("editName").value; } dlg.Control("staticImage").label = ""; dlg.Control("editName").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("btnLocate").enabled = false; dlg.Control("btnApply").visible = false; } function updateDialog(srcTab, scriptCmdData, dlg, argDpi, argInches, strUnits) { strOldTempImage = srcTab.selected_files(0).name; intAltitude = ""; intLatitude = ""; intLongitude = ""; if (Script.Config["image_rotation"] == true && srcTab.selected_files(0).metadata.image.rotation > 0) { dlg.Control("staticImage").label = ""; dlg.Control("staticImage").rotate = 360 - srcTab.selected_files(0).metadata.image.rotation; dlg.Control("staticImage").label = srcTab.selected_files(0).path + "\\" + srcTab.selected_files(0).name; } else { dlg.Control("staticImage").label = ""; dlg.Control("staticImage").rotate = 0; 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("staticPath").label = srcTab.selected_files(0).realpath; 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; DOpus.Output(srcTab.selected_files(0).metadata.image.altitude); DOpus.Output(srcTab.selected_files(0).metadata.image.latitude); DOpus.Output(srcTab.selected_files(0).metadata.image.longitude); if (intAltitude) { intAltitude = intAltitude.toFixed(2); intAltitude = intAltitude + " metres"; dlg.Control("editAltitude").value = intAltitude; } else dlg.Control("editAltitude").value = ""; if (intLatitude) { var absolute = Math.abs(intLatitude); var degrees = Math.floor(absolute); var minutesNotTruncated = (absolute - degrees) * 60; var minutes = Math.floor(minutesNotTruncated); var seconds = ((minutesNotTruncated - minutes) * 60).toFixed(6); var direction = intLatitude >= 0 ? "N" : "S"; if (intLatitude >= 0) { dlg.Control("editLatitude").value = degrees + "° " + minutes + "' " + seconds + "\" " + direction; } else { dlg.Control("editLatitude").value = degrees + "° " + minutes + "' " + seconds + "\" " + direction; } dlg.Control("btnLocate").enabled = true; } else { dlg.Control("editLatitude").value = ""; dlg.Control("btnLocate").enabled = false; } if (intLongitude) { var absolute = Math.abs(intLongitude); var degrees = Math.floor(absolute); var minutesNotTruncated = (absolute - degrees) * 60; var minutes = Math.floor(minutesNotTruncated); var seconds = ((minutesNotTruncated - minutes) * 60).toFixed(6); var direction = intLongitude >= 0 ? "E" : "W"; if (intLatitude >= 0) { dlg.Control("editLongitude").value = degrees + "° " + minutes + "' " + seconds + "\" " + direction; } else { dlg.Control("editLongitude").value = degrees + "° " + minutes + "' " + seconds + "\" " + direction; } dlg.Control("btnLocate").enabled = true; } else { dlg.Control("editLongitude").value = ""; dlg.Control("btnLocate").enabled = false; } 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