blob: 253769b6d9a0773b15e31f5cb8ff1aca75c50f79 [file] [log] [blame]
Ariane1e29812020-03-04 19:26:20 +01001#!/usr/bin/env python3
Ariane1e29812020-03-04 19:26:20 +01002import os
3
4from PIL import Image
5
6path = os.path.dirname(os.path.realpath(__file__))
7
Michael Bestascf31e1b2022-04-10 18:59:55 +03008resources = ["res_1080p/drawable-nodpi",
9 "res_1440p/drawable-nodpi"]
Ariane1e29812020-03-04 19:26:20 +010010
11def generate_smallvariants(resource):
12 global path
13 wallpapers_path = os.path.join(path, resource)
14 clean(wallpapers_path)
15 wallpapers = os.listdir(wallpapers_path)
16
17 for wallpaper in wallpapers:
Ariane1e29812020-03-04 19:26:20 +010018 # Append _small.jpg to the wallpaper
19 wallpaper_small = os.path.splitext(wallpaper)[0] + "_small.jpg"
20 wallpaper_small_path = os.path.join(wallpapers_path, wallpaper_small)
21
22 # Save the wallpaper with 1/4 size to wallpaper_small_path
23 with Image.open(os.path.join(wallpapers_path, wallpaper)) as img:
24 size = int(img.width / 4), int(img.height / 4)
25
26 img_small = img.resize(size, Image.ANTIALIAS)
27 img_small.save(wallpaper_small_path, "JPEG")
28
29def clean(wallpapers_path):
30 wallpapers = os.listdir(wallpapers_path)
31
32 for wallpaper in wallpapers:
33 # Get rid of existing small variants
34 if wallpaper.endswith("_small.jpg"):
35 os.remove(os.path.join(wallpapers_path, wallpaper))
36
37for resource in resources:
38 generate_smallvariants(resource)