Files
XCEngine/editor/rename_color.py

29 lines
821 B
Python

import os
from PIL import Image
def get_dominant_color(image_path):
img = Image.open(image_path).convert("RGB")
img = img.resize((1, 1), Image.Resampling.LANCZOS)
r, g, b = img.getpixel((0, 0))
return r, g, b
def rename_with_color(base_path):
files = ["color.png", "color2.png"]
for f in files:
old_path = os.path.join(base_path, f)
if os.path.exists(old_path):
r, g, b = get_dominant_color(old_path)
new_name = f"color-({r},{g},{b}).png"
new_path = os.path.join(base_path, new_name)
os.rename(old_path, new_path)
print(f"Renamed: {f} -> {new_name}")
else:
print(f"File not found: {old_path}")
if __name__ == "__main__":
base = r"D:\Xuanchi\Main\XCEngine\editor"
rename_with_color(base)