59 lines
1.1 KiB
Bash
Executable File
59 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
dest_dir="$HOME/Pictures/Wallpapers"
|
|
rmflag=0
|
|
|
|
usage() {
|
|
echo "Usage: $0 [-r] <src-file> [src-file ...]"
|
|
echo " -r remove source file after successful conversion"
|
|
exit 2
|
|
}
|
|
|
|
while getopts ":r" opt; do
|
|
case "$opt" in
|
|
r) rmflag=1 ;;
|
|
*) usage ;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
# Require at least one file
|
|
if [ "$#" -lt 1 ]; then
|
|
echo "Error: no source files provided"
|
|
usage
|
|
fi
|
|
|
|
# Check ImageMagick
|
|
if ! command -v magick >/dev/null 2>&1; then
|
|
echo "Error: ImageMagick 'magick' command not found"
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$dest_dir"
|
|
timestamp=$(date +%Y%m%d%H%M%S)
|
|
counter=0
|
|
|
|
# Process each file one by one
|
|
for src in "$@"; do
|
|
if [ ! -e "$src" ]; then
|
|
echo "Error: '$src' does not exist, skipping"
|
|
continue
|
|
fi
|
|
|
|
counter=$((counter + 1))
|
|
|
|
dst="$dest_dir/wallpaper${timestamp}_${counter}.png"
|
|
|
|
if magick -- "$src" "$dst"; then
|
|
echo "Created: $dst"
|
|
if [ "$rmflag" -eq 1 ]; then
|
|
rm -f -- "$src"
|
|
fi
|
|
else
|
|
echo "Error: conversion failed for '$src'"
|
|
fi
|
|
done
|
|
|
|
exit 0
|