BallanceBlenderHelper/bbp_ng/tools/build_icons.py

44 lines
1.2 KiB
Python
Raw Normal View History

2023-11-22 17:41:43 +08:00
import os
2023-12-25 10:49:25 +08:00
import common
2023-11-22 17:41:43 +08:00
import PIL, PIL.Image
# the config for thumbnail
g_ThumbnailSize: int = 16
def resize_image(src_file: str, dst_file: str) -> None:
# open image
src_image: PIL.Image.Image = PIL.Image.open(src_file)
# create thumbnail
src_image.thumbnail((g_ThumbnailSize, g_ThumbnailSize))
# save to new file
src_image.save(dst_file)
def create_thumbnails() -> None:
# get folder path
root_folder: str = os.path.dirname(os.path.dirname(__file__))
2023-12-25 10:49:25 +08:00
# prepare handler
def folder_handler(src_folder: str, dst_folder: str) -> None:
# just create folder
print(f'Creating Folder: {src_folder} -> {dst_folder}')
os.makedirs(dst_folder, exist_ok = True)
def file_handler(src_file: str, dst_file: str) -> None:
# skip non-image
if not src_file.endswith('.png'): return
# call thumbnail func
print(f'Processing Thumbnail: {src_file} -> {dst_file}')
resize_image(src_file, dst_file)
# call common processor
common.common_file_migrator(
os.path.join(root_folder, 'raw_icons'),
os.path.join(root_folder, 'icons'),
folder_handler,
file_handler
)
2023-11-22 17:41:43 +08:00
print('Done.')
if __name__ == '__main__':
create_thumbnails()