-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_smallvariants.py
More file actions
39 lines (28 loc) · 1.2 KB
/
generate_smallvariants.py
File metadata and controls
39 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from PIL import Image
path = os.path.dirname(os.path.realpath(__file__)) + "/"
resources = ["res/drawable-nodpi"]
def generate_smallvariants(resource):
global path
wallpapers_path = path + resource + "/"
clean(wallpapers_path)
wallpapers = os.listdir(wallpapers_path)
for wallpaper in wallpapers:
# Append _small.jpg to the wallpaper
wallpaper_small = wallpaper.split(".")[0] + "_small.jpg"
wallpaper_small_path = wallpapers_path + wallpaper_small
# Save the wallpaper with 1/5 size to wallpaper_small_path
with Image.open(wallpapers_path + wallpaper) as img:
small_width = img.width / 5
small_height = img.height / 5
size = int(small_width), int(small_height)
img_small = img.resize(size, Image.Resampling.LANCZOS)
img_small.convert('RGB').save(wallpaper_small_path, "JPEG")
def clean(wallpapers_path):
wallpapers = os.listdir(wallpapers_path)
for wallpaper in wallpapers:
# Get rid of existing small variants
if wallpaper.endswith("_small.jpg"):
os.remove(wallpapers_path + wallpaper)
for resource in resources:
generate_smallvariants(resource)