Files
Lucas Vivohost 16c69ac7df feat(images): consolidate panorama detection
Combine panorama detection utilities into a single script.

- Merge aspect-ratio based panorama detection with dimension-based
checks
- Detect images with aspect ratio < 0.5 or > 1.8
- Detect images where width exceeds three times the height
- Ignore images already tagged as Panorama
- Scan directories recursively for JPG, JPEG, and PNG files
- Add timestamped logging of detected panorama candidates
- Optionally copy detected panoramas to a review directory
- Improve filename handling using find -print0
- Use identify -format for reliable dimension extraction
- Add dependency validation and robust error handling
- Reduce repeated ImageMagick parsing and simplify maintenance
2026-09-14 12:43:38 +02:00

105 lines
2.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
###############################################################################
# Script Name: find_panoramas.sh
#
# Description:
# Recursively scans a directory for JPG and PNG images and identifies
# potential panorama images using multiple detection methods:
#
# 1. Aspect ratio < 0.5
# 2. Aspect ratio > 1.8
# 3. Width > 3 × Height
#
# Images already tagged as "Panorama" are ignored.
#
# Matching images are:
# - Logged to a timestamped logfile
# - Optionally copied to a review directory
#
# Requirements:
# - Bash
# - ImageMagick (identify)
# - bc
#
# Usage:
# ./find_panoramas.sh
#
###############################################################################
set -euo pipefail
IMG_DIR="/home/lucas/Pictures"
COPY_DIR="/home/lucas/Downloads"
PANORAMA_AR_LT="0.5"
PANORAMA_AR_HT="1.8"
DATE=$(date +"%Y%m%d_%H%M%S")
LOGFILE="${IMG_DIR}/panorama_${DATE}.log"
touch "$LOGFILE"
write_log() {
echo "$@"
echo "$@" >> "$LOGFILE"
}
# Verify dependencies
for cmd in identify bc; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "Error: '$cmd' not found"
exit 1
}
done
find "$IMG_DIR" \
\( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) \
-print0 |
while IFS= read -r -d '' img; do
# Get dimensions
dimensions=$(identify -format "%wx%h" "$img" 2>/dev/null) || {
write_log "Skipping invalid image: $img"
continue
}
width=${dimensions%x*}
height=${dimensions#*x}
# Avoid divide-by-zero
[[ "$height" -eq 0 ]] && continue
# Calculate aspect ratio
aspect_ratio=$(echo "scale=4; $height / $width" | bc -l)
# Skip images already marked Panorama
if identify -verbose "$img" 2>/dev/null | grep -q "Panorama"; then
continue
fi
panorama=false
# Aspect-ratio checks
if (( $(echo "$aspect_ratio < $PANORAMA_AR_LT" | bc -l) )); then
panorama=true
elif (( $(echo "$aspect_ratio > $PANORAMA_AR_HT" | bc -l) )); then
panorama=true
fi
# Width > 3 × Height check
if (( width > height * 3 )); then
panorama=true
fi
if [[ "$panorama" == true ]]; then
write_log "PANORAMA | ${dimensions} | AR=${aspect_ratio} | ${img}"
# Copy for manual review
cp -n "$img" "$COPY_DIR/" 2>/dev/null || true
fi
done
write_log "Scan complete."