diff --git a/image editing/findPanorama.sh b/image editing/findPanorama.sh new file mode 100755 index 0000000..8d3d3eb --- /dev/null +++ b/image editing/findPanorama.sh @@ -0,0 +1,105 @@ +#!/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." \ No newline at end of file diff --git a/quiethost/findPanorama.sh b/quiethost/findPanorama.sh deleted file mode 100755 index 5896295..0000000 --- a/quiethost/findPanorama.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -IFS=$'\n'; set -f -ARR=($(find . \( -name "*.png" -or -name "*.jp*g" \) | grep -v xml)) -unset IFS; set +f -for ((i=0;i<${#ARR[@]};i++)); do - NUM1=$(identify "${ARR[i]}" | rev | cut -f7 -d' ' | rev | cut -f1 -d'x') - NUM2=$(identify "${ARR[i]}" | rev | cut -f7 -d' ' | rev | cut -f2 -d'x') - echo "${ARR[i]}" - if [[ "$NUM1" != "" && $NUM2 != "" ]]; then - if [[ $NUM1 -gt $(( $NUM2 * 3 )) ]]; then - identify "${ARR[i]}" >> panoramaImages.txt - cp "${ARR[i]}" /home/lucas/Downloads/ - fi - fi -done - diff --git a/quiethost/find_panorama.sh b/quiethost/find_panorama.sh deleted file mode 100755 index 6af2b49..0000000 --- a/quiethost/find_panorama.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -DATE="$(date +'%m%d%H%M%S')" -log="logfile_${DATE}.log" -IMG_DIR="/home/lucas/Pictures/" -PANORAMA_AR_LT="0.5" -PANORAMA_AR_HT="1.8" -> "${IMG_DIR}${log}" - -getAspectRatio() { - if [ "$1" == "" ]; then return "0"; fi - identify "$1" | perl -ne '/(.+?)\s+[A-Z]{3,4}\s+(\d+)x(\d+)/; print $3/$2, "\n"' - if [ $? -ne 0 ]; then return "0"; fi -} -write_log() { - echo "$@" - echo "$@" >> "${IMG_DIR}${log}" -} - -IFS=$'\n'; set -f -IMG_ARR=($(find ${IMG_DIR} -name '*.jp*g' -or -name '*.JP*G' -name '*.png')) -for IMG in ${IMG_ARR[@]}; do - imageAR=$(getAspectRatio ${IMG}) - if [ "${imageAR}" != "" ]; then - if [ $(echo ${imageAR}'<'${PANORAMA_AR_LT} | bc -l) -eq 1 ] || [ $(echo ${imageAR}'>'${PANORAMA_AR_HT} | bc -l) -eq 1 ]; then - if [ $(identify -verbose ${IMG} | grep -o "Panorama" | wc -l) -eq 0 ]; then - write_log ${IMG} ${imageAR} - fi - fi - fi -done