from PIL import Image import os imgs = [] remimg = "" noimg = "" Set the input and…
- User
from PIL import Image import os
imgs = [] remimg = "" noimg = ""
Set the input and output directories
input_dir = 'T:/Fivem Related/Alpha Dev/Reduce Big Inventory File Sizes for faster loading!/input/' output_dir = 'T:/Fivem Related/Alpha Dev/Reduce Big Inventory File Sizes for faster loading!/output/'
Set the maximum width and height for resizing the images
max_size = (145, 124)
Loop through all files in the input directory
for filename in os.listdir(input_dir): if filename.endswith('.png'): # Open the image file and reduce its dimensions and bit depth if filename in imgs: with Image.open(input_dir + filename) as img: img = img.convert('RGBA') img.thumbnail(max_size)
# Save the image to the output directory with a reduced file size new_filename = os.path.splitext(filename)[0] + '.png' img.save(output_dir + new_filename, optimize=True, quality=50) else: remimg = remimg + filename + ", "for file in imgs: if not os.path.isfile(input_dir + file): noimg = noimg + file + ", "
print("Unused Images Removed: " + remimg) print("Images Not Found: " + noimg)
- Assistant
This script takes images from an input directory, resizes them according to the specified max_size and compression settings, and saves them to the output directory. It also prints out any unused images that weren't in the input directory.
However, the script has an issue: the variable
imgsis empty, so the if statementsif filename in imgsandif not os.path.isfile(input_dir + file)won't work as intended.