import sys
from PIL import Image
def convert_png_to_ico(png_path, ico_path, size=128):
icon_size = (size, size)
img = Image.open(png_path)
img = img.resize(size=icon_size)
img.save(ico_path)
def print_icon_file_info(ico_path):
ico_image = Image.open(ico_path)
print(f"Image type: {ico_image.format}\nSize: {ico_image.size}")
def main(source_file, target_file, icon_size=128):
allowed_icon_size = (16, 32, 64, 128, 256)
if icon_size not in allowed_icon_size:
print("Error: Invalid icon size.\nAllowed size = 16, 32, 64, 128, 56\n")
return
convert_png_to_ico(source_file, target_file, size=icon_size)
print_icon_file_info(target_file)
if __name__ == '__main__':
if len(sys.argv) == 3:
main(sys.argv[1], f"{sys.argv[1]}.ico", int(sys.argv[2]))
elif len(sys.argv) == 2:
main(sys.argv[1], f"{sys.argv[1]}.ico")
else:
print("Usage: ImageFileName [size]\n")