Coding/Python 삽질기2024. 1. 4. 00:01
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")

'Coding > Python 삽질기' 카테고리의 다른 글

Cardioid 그리기  (0) 2024.02.17
[Python] 프랙탈 나무 만들기  (0) 2023.09.15
[Python] Python 소스 코드 빌드 해보기  (1) 2023.09.06
Posted by chobocho