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