diff options
author | Eric Hameleers <alien@slackware.com> | 2020-12-22 08:38:17 +0000 |
---|---|---|
committer | Eric Hameleers <alien@slackware.com> | 2020-12-22 08:38:17 +0000 |
commit | 66f483167c48e70939db8713a0b262d74243db77 (patch) | |
tree | 0397061a88d759e20102f8e8a90ef30283883353 /daw_base | |
parent | e26563fdeda98f31307178650e03069057562e99 (diff) | |
download | asb-66f483167c48e70939db8713a0b262d74243db77.tar.gz asb-66f483167c48e70939db8713a0b262d74243db77.tar.xz |
Initial revision
Diffstat (limited to 'daw_base')
-rwxr-xr-x | daw_base/build/gen_wallpaper_from_bitmap.sh | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/daw_base/build/gen_wallpaper_from_bitmap.sh b/daw_base/build/gen_wallpaper_from_bitmap.sh new file mode 100755 index 00000000..6116efb5 --- /dev/null +++ b/daw_base/build/gen_wallpaper_from_bitmap.sh @@ -0,0 +1,157 @@ +#!/bin/bash +# +# generate a Plasma5 Wallpaper collection from a single image + +# Parameter '-b': bitmap file of JPG or PNG format. +# Aspect ratio of the image *must* be 16:9 (1920x1080 px or higher res). +# Parameter 2: name of the wallpaper directory (single word) +# Parameter 3: descriptive long name for the wallpaper (between quotes) +# +# Example: +# ./gen_wallpaper_from_bitmap.sh -p sample.png -d LivingFlame -n "The living flame" -a "John Doe" -e "foo@fum.info" +# --------------------------------------------------------------------------- + +CWD=$(cd $(dirname $0); pwd) + +# Attribution - this will be used in the wallpaper metadata file: +WP_AUTHOR=${WP_AUTHOR:-"Eric Hameleers"} +WP_EMAIL=${WP_EMAIL:-"alien@slackware.com"} + +# More default values: +WP_ROOT=${WP_ROOT:-"$CWD"} + +BN=$(basename $0) +SHOWHELP=0 + +# --------------------------------------------------------------------------- +while getopts "a:b:d:e:hn:r:" Option +do + case $Option in + a ) WP_AUTHOR="${OPTARG}" + ;; + b ) WP_BITMAP="${OPTARG}" + ;; + d ) WP_DIR="${OPTARG}" + ;; + e ) WP_EMAIL="${OPTARG}" + ;; + h ) SHOWHELP=1 + ;; + n ) WP_NAME="${OPTARG}" + ;; + r ) WP_ROOT="${OPTARG}" + ;; + * ) ;; # DEFAULT + esac +done + +# End of option parsing. +shift $(($OPTIND - 1)) + +# $1 now references the first non option item supplied on the command line +# if one exists. +# --------------------------------------------------------------------------- + +if [ $SHOWHELP -eq 1 ]; then + echo "[$BN:] Parameters are:" + echo " -a <author> Name of the wallpaper author, put inbetween quotes." + echo " -b <bitmap> Bitmap file in JPG or PNG format." + echo " Aspect ratio of the image *must* be 16:9" + echo " (1920x1080 px or higher res)." + echo " -d <dirname> Directory name for the wallpaper." + echo " -e <email> Email address of the wallpaper author." + echo " -h This help." + echo " -n <name> Descriptive name for the wallpaper, inbetween quotes." + echo " -r <rootdir> Root directory to create the wallpaper" + echo " directory structure in." + exit 0 +fi + +# Some house-keeping with regard to the supplied image: +WP_REALBITMAP="$(readlink -f ${WP_BITMAP} 2>&1)" +WP_REALBASE="$(echo $(basename ${WP_REALBITMAP}) |rev |cut -d. -f2- |rev)" +WP_BITMBASE="$(echo $(basename ${WP_BITMAP}) |rev |cut -d. -f2- |rev)" + +# If wallpaper name / description were not given, we use the bitmap basename: +WP_DIR=${WP_DIR:-"$WP_REALBASE"} +WP_NAME=${WP_NAME:-"$WP_BITMBASE"} + +# Exit immediately if the image file is not found: +if ! readlink -f "${WP_BITMAP}" 1>/dev/null 2>&1 1>/dev/null 2>&1 || ! file "${WP_REALBITMAP}" | grep -q "image data" ; then + echo "-- No wallpaper image found." + exit 1 +fi + +# Exit if the target directory does not exist or is not writable: +if [ ! -d "${WP_ROOT}" ]; then + echo "-- '${WP_ROOT}' not a directory." + exit 2 +fi +# Get the full path: +WP_ROOT="$(cd ${WP_ROOT}; pwd)" +if [ ! -w "${WP_ROOT}" ]; then + echo "-- Directory '${WP_ROOT}' not writable." + exit 2 +fi + +# Exit if the wallpaper already exists: +if [ -d "${WP_ROOT}/${WP_DIR}" ]; then + echo "-- Wallpaper '${WP_ROOT}/${WP_DIR}' already exists." + exit 3 +fi + +# Create the wallpaper for Plasma5; +echo "-- Normalizing background image." +# First convert our image into a JPG with known filename: +TMPDIR=$(mktemp -d -t wp_img.XXXXXX) +convert "${WP_REALBITMAP}" ${TMPDIR}/background.jpg + +# The toplevel directory WP_DIR is your wallpaper! +# It needs to be placed in /usr/share/wallpapers/ on the target system: +mkdir -p ${WP_ROOT}/${WP_DIR}/contents/images + +# Create set of images for common aspect ratios like 16:9, 16:10 and 4:3: +# Aspect Ratio 16:9 : +convert ${TMPDIR}/background.jpg \ + -resize 1920x1080 \ + ${WP_ROOT}/${WP_DIR}/contents/images/1920x1080.jpg +convert ${TMPDIR}/background.jpg \ + -resize 5120x2880 \ + ${WP_ROOT}/${WP_DIR}/contents/images/5120x2880.jpg +# Aspect Ratio 16:10 : +convert ${TMPDIR}/background.jpg \ + -resize 5120x - | \ + convert - -geometry 1920x1200^ -gravity center -crop 1920x1200+0+0 \ + ${WP_ROOT}/${WP_DIR}/contents/images/1920x1200.jpg +convert ${TMPDIR}/background.jpg \ + -resize 5120x - | \ + convert - -geometry 1280x800^ -gravity center -crop 1280x800+0+0 \ + ${WP_ROOT}/${WP_DIR}/contents/images/1280x800.jpg +# Aspect Ratio 4:3 : +convert ${TMPDIR}/background.jpg \ + -resize 5120x - | \ + convert - -geometry 1024x768^ -gravity center -crop 1024x768+0+0 \ + ${WP_ROOT}/${WP_DIR}/contents/images/1024x768.jpg + +# Create the required wallpaper screenshot of 400x225 px (16:9 aspect ratio): +convert ${TMPDIR}/background.jpg \ + -resize 400x225 \ + ${WP_ROOT}/${WP_DIR}/contents/screenshot.png + +# Add wallpaper description: +cat <<EOT >${WP_ROOT}/${WP_DIR}/metadata.desktop +[Desktop Entry] +Name=${WP_NAME} + +X-KDE-PluginInfo-Name=${WP_DIR} +X-KDE-PluginInfo-Author=${WP_AUTHOR} +X-KDE-PluginInfo-Email=${WP_EMAIL} +X-KDE-PluginInfo-License=CC-BY-SA-4.0 +EOT + +# Inform user: +echo "-- Wallpaper '${WP_NAME}' created in '${WP_ROOT}/${WP_DIR}'." + +# Cleanup: +rm -fr $TMPDIR + |