105 lines
2.3 KiB
Bash
105 lines
2.3 KiB
Bash
#!/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."
|