Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def extract_png_chunks(file_path):
- with open(file_path, 'rb') as file:
- signature = file.read(8)
- if signature != b'\x89PNG\r\n\x1a\n':
- raise ValueError("File is not a valid PNG file.")
- print("Signature:", signature)
- while True:
- length_bytes = file.read(4)
- if len(length_bytes) < 4:
- break
- length = int.from_bytes(length_bytes, 'big')
- chunk_type = file.read(4).decode('ascii')
- chunk_data = file.read(length)
- crc = file.read(4).hex()
- print(f"Chunk Type: {chunk_type}")
- print(f" Length: {length} bytes")
- print(f" CRC: {crc}")
- print()
- if chunk_type == 'IEND':
- break
- extract_png_chunks('image.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement