Skip to content

Instantly share code, notes, and snippets.

@autoferrit
Created January 5, 2017 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autoferrit/29568733f0a7ef2115de14b3201df53d to your computer and use it in GitHub Desktop.
Save autoferrit/29568733f0a7ef2115de14b3201df53d to your computer and use it in GitHub Desktop.
#|/bin/bash
#
# use:
# $ ./archify image.jpg [blurring] [logowidth]
# blurring is an integer from 0 (no) to 8 (thick greasy lens)
# logowidth is in pixels
#
bg=$1
blur=${2:-0}
logowidth=${3:-350}
logo="arch_white.svg"
# create temporary files with unique name
tmpbg=$(mktemp -t tmp.XXXX.png)
tmplogo=$(mktemp -t tmp.XXXX.png)
# safely create the file that will contain the wallpaper
outfile="arch_$bg"
if [ -f "$outfile" ];
then
read -r -p "The file $outfile already exists, dou you want to overwrite it? [y/N] " response
response=${response,,} # tolower
if [[ ! "$response" =~ ^(yes|y) ]];
then
outfile=$(mktemp archwall.XXXXX.png)
fi
fi
# scale the image (keeping aspect ratio) to the right size
convert $bg -resize 1600x1080 -blur 0x$blur "$tmpbg"
# turn the vector logo into a bitmap
convert -density 120 -resize $logowidth +antialias -background none $logo "$tmplogo"
# place the logo where it's supposed to be
composite -gravity center "$tmplogo" "$tmpbg" "$outfile"
echo "Created $outfile"
# clean up
rm "$tmpbg" "$tmplogo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment