mirror of
https://github.com/morgan9e/helium
synced 2026-04-15 00:44:06 +09:00
utils/generate_resources: use pathlib for output path
This commit is contained in:
@@ -8,6 +8,7 @@ Generates scaled resources for Helium branding
|
||||
import os
|
||||
import sys
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def scale_image(input_file, size, output_path):
|
||||
@@ -18,7 +19,7 @@ def scale_image(input_file, size, output_path):
|
||||
img.thumbnail((size, size))
|
||||
|
||||
# make sure output path exists
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
os.makedirs(output_path.parent, exist_ok=True)
|
||||
|
||||
img.save(output_path, optimize=True)
|
||||
|
||||
@@ -39,9 +40,9 @@ def generate_resources(resource_list, resource_dir):
|
||||
if len(line_parts) != 3:
|
||||
raise ValueError(f"Line {line_number} in the resource file is invalid.")
|
||||
|
||||
input_file = os.path.join(resource_dir, line_parts[0])
|
||||
input_file = resource_dir / line_parts[0]
|
||||
size = int(line_parts[1])
|
||||
output_file = os.path.join(resource_dir, line_parts[2])
|
||||
output_file = resource_dir / line_parts[2]
|
||||
|
||||
scale_image(input_file, size, output_file)
|
||||
print(f"Created {line_parts[2]}")
|
||||
@@ -57,7 +58,7 @@ def main():
|
||||
sys.exit(1)
|
||||
|
||||
resource_list = sys.argv[1]
|
||||
resource_dir = sys.argv[2]
|
||||
resource_dir = Path(sys.argv[2])
|
||||
|
||||
generate_resources(resource_list, resource_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user