Skip to content

Instantly share code, notes, and snippets.

@bananasmoothii
Last active April 26, 2021 11:32
Show Gist options
  • Save bananasmoothii/9f7a262e68aecde392cfda11174743f8 to your computer and use it in GitHub Desktop.
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
#!/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"
@bananasmoothii
Copy link
Author

bananasmoothii commented Apr 12, 2021

How to install?

  1. install ImageMakick (sudo apt install imagemagick or sudo yum install ImageMagick)
  2. Take a random image and rename it to "bing.jpg"
  3. Go in system settings -> Startup and Shutdown -> Login screen (SDDM) -> (behaviour if it appears) and set that image as background
  4. Save that script in /etc/init.d/ and make it executable (sudo chmod 755 download_bing.sh)
  5. You may want to edit "downloadTo" if your theme isn't Breeze, but the "bing" image should be in the folder you set (in "downloadTo", "bing" is the image, not a folder)
  6. Run the script and see if it works (it may not, I made it for my own personal computer, but I don't see why it should not)
  7. Run 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)
  8. It should be done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment