Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created September 8, 2024 09:55
Show Gist options
  • Save shinshin86/1df07e1a6374906eda6e1fcee0d0d2e1 to your computer and use it in GitHub Desktop.
Save shinshin86/1df07e1a6374906eda6e1fcee0d0d2e1 to your computer and use it in GitHub Desktop.
Check pnginfo script
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment