Dual screen wallpaper script

This is a script written in Python that combines two images into a single dual screen wallpaper so you can have different wallpapers on two monitors. It can be run automatically to randomly change your wallpapers at set intervals. It is intended for Gnome users who like to change their wallpapers often but dislike having to create dual-screen wallpapers in Gimp (like me).

The code is very poorly written and relies on a few assumptions: (1) you have a single, writable directory with wallpapers, (2) this directory contains only image files (jpg, gif, png), (3) either your monitors are the same aspect ratio, or you don’t mind some stretching/squishing (though there’s a half-fix if you read the comments in the code), (4) you’re comfortable editing the first few lines to configure your screen layout. This is my first Python script. It’s not terribly bulletproof or feature rich but it does the job. Once I’m a bit more comfortable with Python, I’ll probably write an improved version with more options and error checking.

Edit the code below and save it somewhere (e.g. ~/.scripts/wallswitcher.py) then execute it with: python ~/.scripts/wallswitcher.py


#! /usr/bin/env python
# Billy Barnes: http://www.webarnes.ca
# Excuse the probable horribleness of the code, this is my very first Python
# script. It's only been an hour since I started learning Python.
#
# Skip these two lines

import os, random, Image, mimetypes
random.seed()

# *Edit* the four values below to reflect your setup.

left_screen = 1680, 1050 # Resolution: width, height
right_screen = 1920, 1200
offsets = 0, 0 # How many pixels to shift each image vertically (if you have monitors at different resolutions bottom-aligned)
image_dir = os.path.expanduser("~") + '/Pictures/Wallpapers/' # Must be writable

#################################################

image_list = os.listdir(image_dir)
if ('Generated Wallpaper.jpg' in image_list):
	image_list.remove('Generated Wallpaper.jpg')

# If you don't like the randomness, you could edit these variables yourself, like so:
# left_image = image_dir + 'Wallpaper1.jpg'
left_image = image_dir + image_list.pop( random.randint(0,len(image_list) - 1) )
right_image = image_dir + image_list.pop( random.randint(0,len(image_list) - 1) )

# Size of your entire desktop
size = left_screen[0] + right_screen[0], left_screen[1] + right_screen[1]

# Opens and scales images
# If only one of your monitors is 4:3, you might want to delete the ".resize(left/right_screen)" part for that monitor
dual_image = Image.new('RGB', size)
left_image = Image.open(left_image).resize(left_screen)
right_image = Image.open(right_image).resize(right_screen)

# Combines images
dual_image.paste(left_image, (0, offsets[0]))
dual_image.paste(right_image, (left_screen[0], offsets[1]))

# Saves combined image in your wallpapers folder
dual_image.save(image_dir + 'Generated Wallpaper.jpg')

Related Post

Read More
Read More
Read More
Read More