mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-08-04 10:14:34 +02:00
wallpaper: handle wide wallpapers
This commit is contained in:
parent
93fe3e3cef
commit
2588551af0
1 changed files with 37 additions and 20 deletions
|
@ -49,14 +49,26 @@ screens.sort(key=lambda screen: -screen[0]*screen[1])
|
||||||
|
|
||||||
# Get as many random image as we have screens
|
# Get as many random image as we have screens
|
||||||
images = []
|
images = []
|
||||||
for root, _, files in os.walk(os.path.join(options.directory)):
|
for base, _, files in os.walk(os.path.join(options.directory)):
|
||||||
for i in files:
|
for i in files:
|
||||||
if string.lower(os.path.splitext(i)[1]) in ('.jpg',
|
if string.lower(os.path.splitext(i)[1]) in ('.jpg',
|
||||||
'.jpeg',
|
'.jpeg',
|
||||||
'.png'):
|
'.png'):
|
||||||
images.append(os.path.join(root, i))
|
images.append(os.path.join(base, i))
|
||||||
images = random.sample(images, len(screens))
|
images = random.sample(images, len(screens))
|
||||||
images = [Image.open(image) for image in images]
|
images = [Image.open(image) for image in images]
|
||||||
|
|
||||||
|
# If more than one screen and one image has the right aspect ratio,
|
||||||
|
# use it.
|
||||||
|
if len(screens) > 1:
|
||||||
|
target = root.width_in_pixels * 100 / root.height_in_pixels
|
||||||
|
ratios = [image.size[0] * 100 / image.size[1] for image in images]
|
||||||
|
try:
|
||||||
|
index = ratios.index(target)
|
||||||
|
images = [images[index]]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
print("wallpaper: {}".format(" + ".join(
|
print("wallpaper: {}".format(" + ".join(
|
||||||
["`%s`" % x.filename[(len(options.directory) + 1):]
|
["`%s`" % x.filename[(len(options.directory) + 1):]
|
||||||
for x in images])))
|
for x in images])))
|
||||||
|
@ -68,25 +80,30 @@ for idx, image in enumerate(images):
|
||||||
os.remove(target)
|
os.remove(target)
|
||||||
os.symlink(os.path.abspath(image.filename), target)
|
os.symlink(os.path.abspath(image.filename), target)
|
||||||
|
|
||||||
for index in range(len(screens)):
|
if len(screens) > 1 and len(images) == 1:
|
||||||
x, y, offsetx, offsety = screens[index]
|
# Wide wallpaper
|
||||||
image = images[index]
|
if image.size != (root.width_in_pixels, root.height_in_pixels):
|
||||||
|
image = image.resize((root.width_in_pixels, root.height_in_pixels),
|
||||||
|
Image.CUBIC)
|
||||||
|
background.paste(image, (0, 0))
|
||||||
|
else:
|
||||||
|
for index in range(len(screens)):
|
||||||
|
x, y, offsetx, offsety = screens[index]
|
||||||
|
image = images[index]
|
||||||
|
|
||||||
# Find the right size for the screen
|
# Find the right size for the screen
|
||||||
imx, imy = x, image.size[1]*x/image.size[0]
|
imx, imy = x, image.size[1]*x/image.size[0]
|
||||||
if (options.crop and imy < y) or (not options.crop and imy > y):
|
if (options.crop and imy < y) or (not options.crop and imy > y):
|
||||||
imx, imy = image.size[0]*y/image.size[1], y
|
imx, imy = image.size[0]*y/image.size[1], y
|
||||||
image = image.resize((imx, imy), Image.CUBIC)
|
if image.size != (imx, imy):
|
||||||
if options.crop:
|
image = image.resize((imx, imy), Image.CUBIC)
|
||||||
image = image.crop(((imx-x)/2, (imy-y)/2,
|
if options.crop:
|
||||||
imx-(imx-x)/2, imy-(imy-y)/2))
|
image = image.crop(((imx-x)/2, (imy-y)/2,
|
||||||
|
imx-(imx-x)/2, imy-(imy-y)/2))
|
||||||
# Include it
|
background.paste(image, (offsetx, offsety))
|
||||||
if options.crop:
|
else:
|
||||||
background.paste(image, (offsetx, offsety))
|
background.paste(image, ((x-imx)/2 + offsetx,
|
||||||
else:
|
(y-imy)/2 + offsety))
|
||||||
background.paste(image, ((x-imx)/2 + offsetx,
|
|
||||||
(y-imy)/2 + offsety))
|
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
assert background, "Don't know the size of the display area"
|
assert background, "Don't know the size of the display area"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue