Files
Server-scripts/image editing/download_visible_spektrum_image_from_wiki.sh
Lucas Vivohost fbcbf008ea feat(wallpapers): automate element spectrum download and panorama generation
Add script for downloading and processing element emission spectra
from Wikimedia Commons.

- Read element definitions from get_images.txt
- Retrieve original spectrum images from Wikimedia Commons
- Download element spectrum PNG files automatically
- Generate standardized filenames using atomic metadata
- Resize images to 3840px width
- Crop images to 3840x540 panorama format
- Export processed files to wallpaper collection directory
- Report missing spectrum images
- Automate creation of element-themed desktop wallpapers
2026-09-14 12:43:38 +02:00

102 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
###############################################################################
# Script Name: get_element_spectra.sh
#
# Description:
# Downloads visible-light emission spectrum images for chemical elements
# from Wikimedia Commons and converts them into panorama wallpapers.
#
# For each entry in get_images.txt, the script:
# 1. Reads element information from the input file.
# 2. Builds a standardized output filename.
# 3. Locates the corresponding spectrum image on Wikimedia Commons.
# 4. Downloads the original PNG file.
# 5. Renames the image using element metadata.
# 6. Resizes the image to 3840 pixels wide.
# 7. Crops the image to 3840x540 pixels.
# 8. Moves the finished panorama wallpaper to the destination folder.
#
# Input Format (get_images.txt):
# element_name atomic_number symbol
#
# Example:
# hydrogen 001 H
# helium 002 He
# lithium 003 Li
#
# Output Example:
# Elements_Panorama_001_H_Hydrogen.png
#
# Requirements:
# - Bash
# - wget
# - ImageMagick (convert)
# - Internet connection
#
# Usage:
# chmod +x get_element_spectra.sh
# ./get_element_spectra.sh
#
# Notes:
# - The script expects get_images.txt in the current directory.
# - Images are downloaded from Wikimedia Commons.
# - Missing images are reported and skipped.
#
###############################################################################
while IFS= read -r line; do
# Build output filename:
# <atomic_number>_<symbol>_<Element>.png
element_name="$(
printf "%s_%s_%s%s\n" \
"$(echo "$line" | cut -f2 -d' ')" \
"$(echo "$line" | cut -f3 -d' ')" \
"$(echo "$line" | cut -f1 -d' ' | head -c 1 | tr 'a-z' 'A-Z')" \
"$(echo "$line" | cut -f1 -d' ' | tail -c +2)"
)"
# Build capitalized element name used by Wikimedia
element="$(
printf "%s%s\n" \
"$(echo "$line" | cut -f1 -d' ' | head -c 1 | tr 'a-z' 'A-Z')" \
"$(echo "$line" | cut -f1 -d' ' | tail -c +2)"
)"
# Retrieve original image URL from Wikimedia Commons
LINK="$(
wget -qO- "https://commons.wikimedia.org/wiki/File:${element}_spectrum_visible.png" \
| grep "Original file" \
| grep -o 'href="[^"]*' \
| tail -c +7
)"
if [ -z "$LINK" ]; then
echo "No spectrum image found for ${element}"
continue
else
echo "Downloading ${element}: ${LINK}"
fi
# Download original image
wget "$LINK"
# Rename downloaded image
mv "${element}_spectrum_visible.png" "${element_name}.png"
# Resize image to 3840 pixels wide
convert "${element_name}.png" \
-resize 3840x \
"${element_name}.png"
# Crop to panorama format
convert "${element_name}.png" \
-crop 3840x540+0+0 \
"${element_name}.png"
# Move final image to wallpaper directory
mv "${element_name}.png" \
"/home/lucas/Documents/Dokumente/Zeug/Wallpaper/Desktop1920x1080/Elements/Elements_Panorama_${element_name}.png"
done < "get_images.txt"