Files
1960-utils/Texturing/OptimizeTextures/optimize_textures.py
2024-03-18 14:42:50 +01:00

34 lines
1.0 KiB
Python

from unittest import skip
from PIL import Image
import sys
import os
if len(sys.argv) < 1:
print("Please provide the input files.")
sys.exit(1)
inputTexs = sys.argv
if not os.path.exists(os.path.join(os.path.dirname(inputTexs[1]),"optimized")):
os.mkdir(os.path.join(os.path.dirname(inputTexs[1]),"optimized"))
export_path = os.path.join(os.path.dirname(inputTexs[1]),"optimized")
#export_path = os.mkdir(os.path.join(os.path.dirname(inputTexs[1]),"optimized"))
#print (Input_filepath)
#print(inputTexs[1])
for i in range(1,len(inputTexs),1):
currentTex = Image.open(inputTexs[i])
if currentTex.size <= (2048,2048):
print (currentTex + "is already smaller than 2048x2048")
continue
# downsize the image with an LANCZOS filter (gives the highest quality)
resizedTex = currentTex.resize((2048,2048),Image.LANCZOS)
resizedTex.save(str(export_path) + "\\" + os.path.basename(inputTexs[i]), optimize=True, quality=95)
print("Textures successfully resized!")