avatar

foyer

wallpaper

Posted on .

screenshot of a file manager showing a folder of images

I have a bunch of images I’ve collected from the internet over the years that I find æsthetically pleasing or inspiring. The trouble is, many of these could have looked great as wallpapers if they weren’t low-res or in portrait orientations. And so, inspired by mood boards, I figured why not use these as wallpapers by selecting a couple of images and scattering them on the screen.

A few weeks in and I’ve been enjoying the surges of inspiration brought in by seeing random juxtaposed images. Every iteration feels like some curated gallery exhibit.

wallpaper
wallpaper
wallpaper

script

wallpaper

Here’s the script if you’d like to try it out. It selects two images from the folder and uses ImageMagick to generate a composite image and feh to set the wallpaper. It also sets the background colour based on one of the selected images.

#!/usr/bin/env bash
# set a random wallpaper
 
# set to your folder of images
moodboard=$HOME/moodboard
cd "$moodboard" || exit
 
dimensions=$(xrandr --current | grep '*' | uniq | awk '{print $1}')
screen_width=$(echo "$dimensions" | cut -d 'x' -f1)
screen_height=$(echo "$dimensions" | cut -d 'x' -f2)
selections=2
width=500
 
images=($(ls | shuf -n $selections))
bg=$(convert "${images[0]}" -resize 1x1! -format '%[pixel:p{0,0}]' info:-)
 
collage=()
for image in "${images[@]}"; do
  x=$((RANDOM % ($screen_width - width)))
  y=$((RANDOM % ($screen_height - width)))
  collage+=("$image -geometry "$width"x"$width">+$x+$y -composite")
done
 
convert -size $dimensions xc:"$bg" ${collage[@]} -append ~/.cache/wall.jpg
feh --bg-fill ~/.cache/wall.jpg

caveat

Image selection ($images) fails when there’s spaces in the file name — something to do with convert. You could simply replace spaces with underscores:

rename "s/ /_/g" *

If you found a fix for this, please let me know :>


—josh