Last active
April 26, 2021 11:32
-
-
Save bananasmoothii/9f7a262e68aecde392cfda11174743f8 to your computer and use it in GitHub Desktop.
Download the daily bing background and set it as Kubuntu's sddm background image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# configuration: | |
xmlProvider="http://bing.com" | |
xmlLink="/HPImageArchive.aspx?format=xml&idx=0&n=1" | |
xmlImageTag="url" | |
xmlDescTag="headline" | |
xmlDesc2Tag="copyright" | |
downloadTo="/usr/share/sddm/themes/breeze/bing.jpg" | |
descSize=50 | |
desc2Size=24 | |
descFont="Laksaman" | |
descColor="white" | |
# these are multipliers of width and height of the image, if the image is 500 pixels tall | |
# and yDesc is set to 0.1, the description will be written at 500*0.1=50 pixels from top-left corner | |
# it must be between 0 and 1 | |
xDesc=0.065 | |
yDesc=0.88 | |
x2Desc=0.065 | |
y2Desc=0.93 | |
desc2Font="Laksaman" | |
# get xml data from bing | |
xml=$(curl -sS "$xmlProvider$xmlLink") | |
imageLink=$(grep -oPm1 "(?<=<$xmlImageTag>)[^<]+" <<< "$xml") | |
imageDesc=$(grep -oPm1 "(?<=<$xmlDescTag>)[^<]+" <<< "$xml") | |
imageDesc2=$(grep -oPm1 "(?<=<$xmlDesc2Tag>)[^<(]+" <<< "$xml") | |
# download the image from bing | |
curl -sS "$xmlProvider$imageLink" -o "/tmp/bing.jpg" | |
# defines width and height | |
width=$(identify -format '%w' "/tmp/bing.jpg") | |
height=$(identify -format '%h' "/tmp/bing.jpg") | |
# defines coordinates for the main description (or "title") | |
x=$(echo "scale=0; $width * $xDesc / 1" | bc) | |
y=$(echo "scale=0; $height * $yDesc / 1" | bc) | |
# writes the main description on the picture | |
convert -font $descFont -pointsize $descSize -fill $descColor -draw "text $x,$y \"$imageDesc\"" /tmp/bing.jpg /tmp/bing.jpg | |
# same for second description | |
x=$(echo "scale=0; $width * $x2Desc / 1" | bc) | |
y=$(echo "scale=0; $height * $y2Desc / 1" | bc) | |
convert -font $desc2Font -pointsize $desc2Size -fill $descColor -draw "text $x,$y \"$imageDesc2\"" /tmp/bing.jpg /tmp/bing.jpg | |
sudo cp /tmp/bing.jpg "$downloadTo" | |
echo "Successfully downloaded daily bing image: $imageDesc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to install?
sudo apt install imagemagick
orsudo yum install ImageMagick
)/etc/init.d/
and make it executable (sudo chmod 755 download_bing.sh
)sudo ln -s /etc/init.d/download_bing.sh /etc/rc3.d/S02download_bing
(creates a symbolic link to a folder where it will be run on startup)