Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created September 8, 2024 09:55
Show Gist options
  • Select an option

  • Save shinshin86/1df07e1a6374906eda6e1fcee0d0d2e1 to your computer and use it in GitHub Desktop.

Select an option

Save shinshin86/1df07e1a6374906eda6e1fcee0d0d2e1 to your computer and use it in GitHub Desktop.

Revisions

  1. shinshin86 created this gist Sep 8, 2024.
    24 changes: 24 additions & 0 deletions checkpnginfo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    from PIL import Image
    import sys

    def get_png_info(file_path):
    try:
    with Image.open(file_path) as img:
    if img.format != 'PNG':
    return "This is not a PNG image."

    info = img.info
    result = "PNG Information:\n"
    for key, value in info.items():
    result += f"{key}: {value}\n"

    return result
    except Exception as e:
    return f"An error occurred: {str(e)}"

    if __name__ == "__main__":
    if len(sys.argv) != 2:
    print("Usage: python checkpnginfo.py <path_to_png_file>")
    else:
    file_path = sys.argv[1]
    print(get_png_info(file_path))