Skip to content

Instantly share code, notes, and snippets.

@foopod
Last active February 10, 2022 23:16
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 foopod/603755546dd9b2f4aae9f94e23e6189d to your computer and use it in GitHub Desktop.
Save foopod/603755546dd9b2f4aae9f94e23e6189d to your computer and use it in GitHub Desktop.
script to create and set wallpaper to photos taken from Nasa's EPIC API
#!/bin/bash
TYPE="natural" # natural or enhanced https://epic.gsfc.nasa.gov/about
declare -i XRES=1920
declare -i YRES=1080
declare -i E_RADIUS=$(($YRES * 80 / 100))
DIR=~/.wallpaper
TIMEOFFSET=3 # 3 days in the past (service runs 1-2 days behind + time difference)
XOFFSET=$(( $XRES / 2 - $E_RADIUS / 2))
YOFFSET=$(( $YRES / 2 - $E_RADIUS / 2))
MONTH=$(date --date="${dataset_date} -$TIMEOFFSET day" +%m)
DAY=$(date --date="${dataset_date} -$TIMEOFFSET day" +%d)
YEAR=$(date --date="${dataset_date} -$TIMEOFFSET day" +%Y)
CURRENTEPOCTIME=`date +"%s"`
DATAURL=https://epic.gsfc.nasa.gov/api/$TYPE/date/$YEAR-$MONTH-$DAY
if [ ! -d $DIR ]; then
mkdir $DIR
fi
NAME=$(curl --silent $DATAURL | jq -r '.[0].image')
IMAGEURL=https://epic.gsfc.nasa.gov/archive/$TYPE/$YEAR/$MONTH/$DAY/png/$NAME.png
curl --silent $IMAGEURL -o $DIR/cover.png
convert $DIR/cover.png \
-blur 0x16 \
-modulate 90,120,100 \
-resize ${XRES}x${YRES}^ \
-gravity center \
-extent ${XRES}x${YRES} \
$DIR/cover_blurred.png
convert $DIR/cover.png \
-resize ${E_RADIUS}x${E_RADIUS}^ \
-background none -fuzz 15% -transparent black \
-alpha set -virtual-pixel transparent \
-channel A -blur 0x2 -level 20%,100% +channel \
$DIR/cover_s.png
rm $DIR/background*
magick $DIR/cover_blurred.png $DIR/cover_s.png \
-compose over \
-geometry +$XOFFSET+$YOFFSET \
-composite $DIR/background-$CURRENTEPOCTIME.png
gsettings set org.gnome.desktop.background picture-uri "file:///"$DIR/background-$CURRENTEPOCTIME.png
@foopod
Copy link
Author

foopod commented Feb 10, 2022

Requires ImageMagick.

Also if not using gnome, you can use feh to set the current background in most x11 systems

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