35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from unittest import skip
|
|
from PIL import Image
|
|
import sys
|
|
import os
|
|
import time
|
|
|
|
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")
|
|
|
|
print("Starting optimization of " + str(len(inputTexs)-1) + " Files")
|
|
|
|
for i in range(1,len(inputTexs),1):
|
|
currentTex = Image.open(inputTexs[i])
|
|
|
|
if currentTex.size <= (2048,2048):
|
|
print (f"{os.path.basename(inputTexs[i])} 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 (os.path.basename(inputTexs[i]) + " successfully converted " + "(" + str(i) + "/" + str(len(inputTexs)-1) + ")")
|
|
|
|
print("Textures successfully resized!")
|
|
time.sleep(5) |