From 804e17dbe68bc791c0565b8113e55a307399b844 Mon Sep 17 00:00:00 2001 From: Lucas Vivohost Date: Mon, 14 Sep 2026 10:35:01 +0200 Subject: [PATCH] feat(images): add wallpaper candidate collection utility feat(images): automate wallpaper preparation and filtering - Recursively scan image directories for JPG, JPEG, and PNG files - Normalize filenames by replacing spaces with underscores - Convert JPG/JPEG images to PNG format - Calculate image aspect ratios automatically - Filter images using configurable wallpaper criteria - Validate minimum image width requirements - Optionally copy matching wallpapers to a collection folder - Provide progress reporting during processing - Add script documentation, requirements, and usage examples --- image editing/getImgaeRatio.sh | 141 +++++++++++++++++++++++++++++++++ quiethost/getImgaeRatio.sh | 35 -------- 2 files changed, 141 insertions(+), 35 deletions(-) create mode 100755 image editing/getImgaeRatio.sh delete mode 100755 quiethost/getImgaeRatio.sh diff --git a/image editing/getImgaeRatio.sh b/image editing/getImgaeRatio.sh new file mode 100755 index 0000000..d613e03 --- /dev/null +++ b/image editing/getImgaeRatio.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +############################################################################### +# Script Name: collect-wallpapers.sh +# +# Description: +# Scans a directory tree for image files and prepares them for wallpaper use. +# +# The script: +# 1. Searches recursively for JPG, JPEG, and PNG images. +# 2. Renames files by replacing spaces with underscores. +# 3. Converts JPG/JPEG images to PNG format. +# 4. Calculates image aspect ratio and width. +# 5. Identifies images matching a target screen aspect ratio. +# 6. Optionally copies matching images to a wallpaper collection folder. +# +# Matching Criteria: +# - Aspect ratio close to 16:9 portrait (0.5625) +# - Configurable tolerance range +# - Minimum image width requirement +# +# Requirements: +# - Bash +# - ImageMagick (identify, convert) +# - bc +# +# Usage: +# +# Scan only: +# ./collect-wallpapers.sh +# +# Scan and copy matching images: +# ./collect-wallpapers.sh -m +# +# Examples: +# +# Analyze images: +# ./collect-wallpapers.sh ~/Pictures +# +# Collect wallpaper candidates: +# ./collect-wallpapers.sh ~/Pictures -m +# +# Output: +# Matching files are copied to: +# +# /data/Ubuntu_Data/Videos/.stuff/ +# +# Notes: +# - JPG/JPEG files are converted to PNG. +# - Spaces in filenames are replaced with underscores. +# - Original PNG files remain unchanged. +# - Original JPG/JPEG files are removed after conversion. +# +############################################################################### + +if [ $# -lt 1 ]; then + echo "Usage: $0 [-m]" + exit 1 +fi + +IMG_PATH="$1" + +MOVE=false +if [ "$2" == "-m" ]; then + MOVE=true +fi + +echo "Path: $IMG_PATH" + +find "$IMG_PATH" \( -name "*.png" -o -name "*.jp*g" \) + +files="$(find "$IMG_PATH" \( -name "*.png" -o -name "*.jp*g" \) | wc -l)" + +printf "%s Files, Move: %s\n" "$files" "$MOVE" + +read -n 1 -s -r -p "Press any key to continue" +printf "\n" + +minImgX="1400" +screenAR="0.5625" +AR_tolerance="0.2" + +counter=0 + +find "$IMG_PATH" \( -name "*.png" -o -name "*.jp*g" \) | while read -r img; do + + ((counter++)) + + object_path="$(dirname "$img")/" + img="$(basename "$img")" + + # Replace spaces with underscores + if [[ "$img" == *" "* ]]; then + new_img="$(echo "$img" | sed 's/ \+/_/g')" + + mv "${object_path}${img}" "${object_path}${new_img}" + + img="$new_img" + fi + + # Convert JPG/JPEG to PNG + if echo "$img" | grep -qiE '\.jpe?g$'; then + + convert "${object_path}${img}" \ + "${object_path}$(echo "$img" | sed 's/\.[jJ][pP][eE]\?[gG]$/.png/')" + + rm "${object_path}${img}" + + img="$(echo "$img" | sed 's/\.[jJ][pP][eE]\?[gG]$/.png/')" + fi + + # Get image dimensions + dimensions="$(identify -format "%wx%h" "${object_path}${img}" 2>/dev/null)" + + width="${dimensions%x*}" + height="${dimensions#*x}" + + if [[ -z "$width" || -z "$height" || "$height" -eq 0 ]]; then + continue + fi + + # Calculate aspect ratio (height / width) + imageAR="$(echo "scale=6; $height / $width" | bc -l)" + + # Match wallpaper criteria + if [[ "$MOVE" == true \ + && $(echo "$imageAR < $screenAR*(1+$AR_tolerance)" | bc -l) -eq 1 \ + && $(echo "$imageAR > $screenAR*(1-$AR_tolerance)" | bc -l) -eq 1 \ + && $(echo "$width > $minImgX" | bc -l) -eq 1 ]]; then + + printf "%d/%s: %s\t%s\n" \ + "$counter" \ + "$files" \ + "$img" \ + "$imageAR" + + cp "${object_path}${img}" \ + "/data/Ubuntu_Data/Videos/.stuff/" + fi + +done \ No newline at end of file diff --git a/quiethost/getImgaeRatio.sh b/quiethost/getImgaeRatio.sh deleted file mode 100755 index 0fbcc24..0000000 --- a/quiethost/getImgaeRatio.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -if [ $# -lt 1 ]; then echo "No Path given"; exit 1; fi -IMG_PATH="$1" -if [ "$2" == "-m" ]; then MOVE=true; fi -MOVE=false -echo Path: $IMG_PATH -find "$IMG_PATH" \( -name "*.png" -or -name "*.jp*g" \) -files="$(find "$IMG_PATH" \( -name "*.png" -or -name "*.jp*g" \) | wc -l)" -printf "%s Files, Move: %s\n" "$files" "$MOVE" -read -n 1 -s -r -p "Press any key to continue" -printf "\n" -minImgX="1400" -screenAR="0.5625" -AR_tolerance="0.2" -counter=0 -find "$IMG_PATH" \( -name "*.png" -or -name "*.jp*g" \) | while read img; do - ((counter++)) - object_path="$(echo "${img}" | rev | cut -f2- -d'/' | rev)/" - img="$(echo "${img}" | rev | cut -f1 -d'/' | rev)" - if [ "$(echo "${img}" | grep " ")" != "" ]; then - mv "${object_path}${img}" "${object_path}$(echo "${img}" | sed 's/ \+/_/g')" - img="$(echo "${img}" | sed 's/ \+/_/g')" - fi - if [ "$(echo "${img}" | grep -e "jp[e]\?g")" != "" ]; then - convert "${object_path}${img}" "${object_path}$(echo "${img}" | sed 's/jp[e]\?g/png/g')" - rm "${object_path}${img}" - img="$(echo "${img}" | sed 's/jp[e]\?g/png/g')" - fi - imageAR=$(identify "${object_path}${img}" | perl -ne '/(.+?)\s+[A-Z]{3}\s+(\d+)x(\d+)/; print $3/$2, "\n"') - imgX=$(identify "${object_path}${img}" | cut -f3 -d' ' | cut -f1 -d'x') - if [[ "$MOVE" = true && $(echo ${imageAR}'<'${screenAR}'*(1+'${AR_tolerance}')' | bc -l) -eq 1 && $(echo ${imageAR}'>'${screenAR}'*(1-'${AR_tolerance}')' | bc -l) -eq 1 && $(echo ${imgX}'>'${minImgX} | bc -l ) -eq 1 ]] ;then - printf "%d/%s: %s\t%s\n" "$counter" "$files" "${img}" "$imageAR" - cp "${object_path}${img}" "/data/Ubuntu_Data/Videos/.stuff/" - fi -done