Arian | e1e2981 | 2020-03-04 19:26:20 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Arian | e1e2981 | 2020-03-04 19:26:20 +0100 | [diff] [blame] | 2 | import os |
| 3 | |
| 4 | from PIL import Image |
| 5 | |
| 6 | path = os.path.dirname(os.path.realpath(__file__)) |
| 7 | |
Michael Bestas | cf31e1b | 2022-04-10 18:59:55 +0300 | [diff] [blame] | 8 | resources = ["res_1080p/drawable-nodpi", |
| 9 | "res_1440p/drawable-nodpi"] |
Arian | e1e2981 | 2020-03-04 19:26:20 +0100 | [diff] [blame] | 10 | |
| 11 | def 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: |
Arian | e1e2981 | 2020-03-04 19:26:20 +0100 | [diff] [blame] | 18 | # 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 | |
| 29 | def 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 | |
| 37 | for resource in resources: |
| 38 | generate_smallvariants(resource) |