summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-11 10:14:30 +0300
committerPaul Buetow <paul@buetow.org>2026-06-11 10:14:30 +0300
commit0aa58bf31f37eab93a2810d38874fbb0c01f6493 (patch)
tree24fedf2c426dad06432de233ed1468275bd62adb /src
parent1b1e3a0a6dc09b9729370db6547b399c43fe8f67 (diff)
Add EXIF tooltip to details view
Diffstat (limited to 'src')
-rw-r--r--src/lib/album.source.sh95
-rw-r--r--src/lib/template.source.sh6
2 files changed, 100 insertions, 1 deletions
diff --git a/src/lib/album.source.sh b/src/lib/album.source.sh
index 0efff6e..5652a5e 100644
--- a/src/lib/album.source.sh
+++ b/src/lib/album.source.sh
@@ -202,6 +202,94 @@ photo_exif_details_html() {
printf '</table>\n'
}
+_first_exif_value_to() {
+ local -n output_ref="$1"; shift
+ local -n exif_ref="$1"; shift
+ local key
+
+ output_ref=''
+ for key in "$@"; do
+ if [ -n "${exif_ref[$key]:-}" ]; then
+ # shellcheck disable=SC2034
+ output_ref="${exif_ref[$key]}"
+ return
+ fi
+ done
+}
+
+photo_exif_tooltip_text() {
+ local -r photo="$1"; shift
+ local -r photo_path="$1"; shift
+ local aperture
+ local camera
+ local date_time
+ local iso
+ local key
+ local line
+ local make
+ local model
+ local separator=''
+ local shutter_speed
+ local -A exif_values=()
+ local -a tooltip_parts=()
+
+ while IFS= read -r line; do
+ if [[ "$line" =~ ^[[:space:]]*exif:([^:]+):[[:space:]]*(.*)$ ]]; then
+ exif_values["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}"
+ fi
+ done < <(cached_photo_identify_output "$photo" "$photo_path")
+
+ make="${exif_values[Make]:-}"
+ model="${exif_values[Model]:-}"
+ camera="$make"
+ if [ -n "$model" ]; then
+ if [ -n "$make" ]; then
+ case "$model" in
+ "$make"|"$make "*)
+ camera="$model"
+ ;;
+ *)
+ camera="$make $model"
+ ;;
+ esac
+ else
+ camera="$model"
+ fi
+ fi
+
+ _first_exif_value_to aperture exif_values FNumber ApertureValue
+ _first_exif_value_to iso exif_values \
+ ISOSpeedRatings PhotographicSensitivity ISO
+ _first_exif_value_to shutter_speed exif_values \
+ ExposureTime ShutterSpeedValue
+ _first_exif_value_to date_time exif_values \
+ DateTimeOriginal DateTimeDigitized DateTime
+
+ if [ -n "$camera" ]; then
+ tooltip_parts+=("Camera: $camera")
+ fi
+ if [ -n "$aperture" ]; then
+ tooltip_parts+=("Aperture: $aperture")
+ fi
+ if [ -n "$iso" ]; then
+ tooltip_parts+=("ISO: $iso")
+ fi
+ if [ -n "$shutter_speed" ]; then
+ tooltip_parts+=("Shutter speed: $shutter_speed")
+ fi
+ if [ -n "$date_time" ]; then
+ tooltip_parts+=("Taken: $date_time")
+ fi
+
+ for key in "${tooltip_parts[@]}"; do
+ printf '%s%s' "$separator" "$key"
+ separator='; '
+ done
+ if (( ${#tooltip_parts[@]} > 0 )); then
+ printf '\n'
+ fi
+}
+
render_details_page() {
local -r html_dir="$1"; shift
local -r photos_dir="$1"; shift
@@ -213,6 +301,7 @@ render_details_page() {
local -r photo_file="$1"; shift
local animation_class
local exif_details_html
+ local exif_tooltip_text
template header "$page_num-$preview_num-details.html" \
html_dir "$html_dir" \
@@ -225,6 +314,9 @@ render_details_page() {
exif_details_html=$(
photo_exif_details_html "$photo_file" "$INCOMING_DIR/$photo_file"
)
+ exif_tooltip_text=$(
+ photo_exif_tooltip_text "$photo_file" "$INCOMING_DIR/$photo_file"
+ )
template details "$page_num-$preview_num-details.html" \
html_dir "$html_dir" \
backhref "$backhref" \
@@ -233,7 +325,8 @@ render_details_page() {
preview_num "$preview_num" \
photo "$photo_file" \
animation_class "$animation_class" \
- exif_details "$exif_details_html"
+ exif_details "$exif_details_html" \
+ exif_tooltip "$exif_tooltip_text"
template footer "$page_num-$preview_num-details.html" \
html_dir "$html_dir" \
backhref "$backhref" \
diff --git a/src/lib/template.source.sh b/src/lib/template.source.sh
index 5c00176..87f73b1 100644
--- a/src/lib/template.source.sh
+++ b/src/lib/template.source.sh
@@ -250,6 +250,7 @@ validate_template_context() {
animation_class
backhref
exif_details
+ exif_tooltip
page_num
photo
photos_dir
@@ -341,6 +342,8 @@ serialize_template_render_context() {
serialize_template_render_var render_enter_page_html "$render_enter_page_html"
serialize_template_render_var \
render_exif_details_html "$render_exif_details_html"
+ serialize_template_render_var \
+ render_exif_tooltip_html "$render_exif_tooltip_html"
serialize_template_render_var render_height_html "$render_height_html"
serialize_template_render_var render_html_dir_html "$render_html_dir_html"
serialize_template_render_var \
@@ -388,6 +391,8 @@ prepare_template_render_vars() {
html_escape_to render_enter_page_html "$context_value"
template_context_value_to render_exif_details_html \
"$context_name" exif_details
+ template_context_value_to context_value "$context_name" exif_tooltip
+ html_escape_to render_exif_tooltip_html "$context_value"
html_escape_to render_height_html "${HEIGHT:-}"
html_escape_to render_html_dir_html "$render_html_dir"
html_escape_to render_maxpreviews_html "${MAXPREVIEWS:-}"
@@ -457,6 +462,7 @@ render_template() {
local render_current_date_text
local render_enter_page_html
local render_exif_details_html
+ local render_exif_tooltip_html
local render_height_html
local render_html_dir
local render_html_dir_html