57 lines
1.2 KiB
Bash
Executable File
57 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Folder with full-size wallpapers
|
|
WALLPAPER_DIR="$HOME/Pictures/Wallpapers"
|
|
|
|
# Folder to store thumbnails
|
|
THUMB_DIR="$HOME/.cache/wallpaper-thumbs"
|
|
|
|
if [ ! -d $THUMB_DIR ]; then
|
|
mkdir -p $THUMB_DIR;
|
|
fi
|
|
|
|
|
|
# Make sure the thumb directory exists
|
|
mkdir -p "$THUMB_DIR"
|
|
|
|
# Max width/height of the thumbnails
|
|
MAX_DIM=300
|
|
|
|
num=0
|
|
|
|
# Process each image
|
|
for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do
|
|
# Skip if no files match
|
|
[ -e "$img" ] || continue
|
|
|
|
# Get just the filename
|
|
fname=$(basename "$img")
|
|
name="${fname%.*}"
|
|
ext="${fname##*.}"
|
|
|
|
# no magick file:
|
|
temp_image_name="$THUMB_DIR/${name}_tmp.${ext}"
|
|
|
|
# Output path
|
|
thumb="$THUMB_DIR/$fname"
|
|
|
|
# If thumbnail already exists and is newer than the original, skip
|
|
if [ -f "$thumb" ] && [ "$thumb" -nt "$img" ]; then
|
|
continue
|
|
fi
|
|
|
|
num+=1
|
|
|
|
# Generate thumbnail using ImageMagick
|
|
if [ -x "/usr/bin/magick" ] then
|
|
magick "$img" -resize "${MAX_DIM}x${MAX_DIM}" "$thumb"
|
|
rm $temp_image_name
|
|
else
|
|
if [ -f "$temp_image_name" ] && [ "$temp_image_name" -nt "$img" ]; then
|
|
continue
|
|
fi
|
|
cp $img $temp_image_name
|
|
fi
|
|
done
|
|
|
|
echo "$num Thumbnails generated in $THUMB_DIR" |