Skip to content

Instantly share code, notes, and snippets.

@mehargags
Last active February 23, 2025 12:03
Show Gist options
  • Save mehargags/5f94ae0ac896bcf85ee13015c2909595 to your computer and use it in GitHub Desktop.
Save mehargags/5f94ae0ac896bcf85ee13015c2909595 to your computer and use it in GitHub Desktop.
VNC-BG-Wallpaper-Creator
#!/bin/bash
### HOW TO RUN ####
### GISTURL="https://gist.github.com/mehargags/5f94ae0ac896bcf85ee13015c2909595/raw"
### echo ${GISTURL}
### curl -s -L ${GISTURL}| bash
### or
### bash <(curl -s -L $GISTURL)
###
# Define the color list
colors=(
"373f51"
"1b1b1e"
"023047"
"283618"
"606c38"
"bc6c25"
"003049"
"9d8189"
"344e41"
"3a5a40"
"415a77"
"03045e"
"432818"
"6f1d1b"
"bb9457"
"264653"
"1d2d44"
"78290f"
"540b0e"
"343a40"
"495057"
"9b2226"
"4f772d"
"bc4749"
"370617"
"003f88"
"583101"
"603808"
"6f4518"
"274c77"
"8b8c89"
"8c2f39"
"3c096c"
"9e0059"
"7f5539"
"251f47"
"2F064C"
)
# Function to convert HEX to RGB
hex_to_rgb() {
hex="$1"
r=$((16#${hex:0:2}))
g=$((16#${hex:2:2}))
b=$((16#${hex:4:2}))
echo "$r,$g,$b"
}
# Check if ImageMagick is installed
if ! command -v convert &> /dev/null; then
echo "ImageMagick is not installed. Installing..."
apt-get update && apt-get install -y imagemagick curl
fi
# Remove existing image if it exists
if [ -f "system_info.jpg" ]; then
rm -f system_info.jpg
fi
# Get system information
IP=$(curl -s ipinfo.io/ip)
RAM=$(free -h | awk '/^Mem:/ {print $2}')
CPU=$(lscpu | awk -F': +' '/Model name:/ && !/BIOS/ {print $2}')
CORES=$(nproc)$(awk -F': ' '/cpu MHz/ {printf "%.1f GHz", $2/1000; exit}' /proc/cpuinfo)
STOR=$(df -h | awk '{ if ($2 ~ /[0-9.]+G/ && $2+0 > 20) print $2 }' | grep -v '^/boot' | sort)
RGN=$(curl -s "https://ipapi.co/$(curl -s ipinfo.io/ip)/json" | jq -r '[.country_name, .region, .city] | join(", ")')
# Select a random color
RANDOM_HEX=${colors[$RANDOM % ${#colors[@]}]}
RGB_COLOR=$(hex_to_rgb "$RANDOM_HEX")
# Create the image with the random background color
convert -size 1152x720 xc:"rgb($RGB_COLOR)" \
-fill white \
-font DejaVu-Sans \
-pointsize 18 \
-gravity southeast \
-interline-spacing 6 \
-annotate +100+100 "${IP} | ${CORES}C / ${RAM} / ${STOR}B \n${CPU} \n${RGN}" \
system_info.jpg
# Check if the image was created successfully
if [ -f "system_info.jpg" ]; then
echo "Image created successfully as system_info.jpg with background color #$RANDOM_HEX (RGB: $RGB_COLOR)"
else
echo "Failed to create image"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment