It is no secret that satellite images allow us to see the full beauty of the Earth's surface from a birds-eye view. Especially with modern high resolution satellite imagery such as from the Sentinel sensors, the diversity of landscapes can be experienced by everybody. This is why, in my opinion, satellite images make for awesome immersive wallpapers. One perfect example is set by the ESA Copernicus Sentinels calendars collection. In 2021, the focus of these well curated monthly satellite image wallpapers be on the megacities of the world, home to hundreds of millions of people worldwide. And even more awesome is that they are provided freely available to everybody.

/posts/img/sentinel_calendar_202102.jpg
Copernicus Sentinel 2 calendar image for February 2021: The megacity Lima, Peru – © ESA 2021

After a colleague showed me this yearly collection of wallpapers last year, the only logical next step for me was to overengineer the hell out of an automatic downloader and wallpaper setter script for them. What else…🤔? My plan was to automatically set the wallpaper per month via a startup script. So this is what I did. In this post I will dissect the script and elaborate on some design decisions. You can always find the latest version of the script in my collection of shell scripts.

Running the script only needs a few minor dependencies: feh, GNU wget, GNU grep and ImageMagick. They should be available in the repository of any Linux distribution. Although most systems will already include most of them, on Arch Linux you can install them through the following command if necessary:

sudo pacman -S feh wget grep imagemagick

As for the script itself, first we need to determine the current month and year. Also, we create a cache folder where the image files will be stored.

YEAR=$(date +%Y)
MNTH=$(date +%m)

mkdir -p ~/.cache/wp/

Then we set the cache file and provide the URL template for the download. The current month and year will be provided by the aforementioned variables.

CACHE_FILE=~/.cache/wp/sentinel_calendar_$YEAR$MNTH.jpg
URL="https://esamultimedia.esa.int/multimedia/eo/calendar"$YEAR"/"$YEAR"_Sentinels_digital_calendar_FB_TW%20feed_1920x1080_$MNTH.jpg"

Then, if the file has not been cached before, attempts to download will be repeated until the download was successful after a five-second delay. The image is saved to the previously definded cache location. This was specifically included since I also wanted to also use the script on a laptop on which it might take a while until a wireless network connection is established.

if [ ! -f $CACHE_FILE ]; then
    until wget $URL -O $CACHE_FILE &> /dev/null
    do
	echo "No success... Wait and retry"
        sleep 5
    done
fi

Since the images are provided in a 16:9 aspect ratio and I use 16:10 monitors on my desktop PCs, I wanted to find a nice way to scale it to the monitor without just having black bars at the top and bottom. So, the average color of the image is calculated by rescaling the entire image to one pixel and returning it to standard out. Piping it into grep allows to extract the color as hex value which will be used later to set a backgroud.

BG_COL=$(convert $CACHE_FILE -resize 1x1 txt:- | grep -Po "#[[:xdigit:]]{6}")

Eventually, the background is set using feh. The background is scaled to fit the maximum size that fits the screen with borders on one side. These borders are then colored with the derived $BG_COL color.

feh -B "$BG_COL" --bg-max $CACHE_FILE

Now, once the script is made executable, it can be run from the command line. I, for example, run it as part of my autostart sequence.

chmod +x copernicus_wallpaper.sh
./copernicus_wallpaper.sh

Of course, this is just one possible take on solving this non-problem. If you see any room for improvement, feel free to open an issue.