Created
September 8, 2024 09:55
-
-
Save shinshin86/1df07e1a6374906eda6e1fcee0d0d2e1 to your computer and use it in GitHub Desktop.
Check pnginfo script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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