from PIL import Image
import os
def compress_run(filename):
new_filename = f"new_{filename}"
try:
im = Image.open(filename)
# x, y = im.size
q = 64
out = im.resize((q, q), Image.ANTIALIAS)
out.save(new_filename)
except Exception as e:
print(f"[error]msg: {e}")
else:
return new_filename
def get_path_filenames(path):
filenames = []
for root, dirs, files in os.walk(path):
for file in files:
if os.path.splitext(file)[1] == ".png":
filenames.append(os.path.join(root, file))
return filenames
if __name__ == '__main__':
filenames = get_path_filenames("country_img")
for f in filenames:
compress_run(f)
print(filenames)