import zlib
import struct
def create_chunk(type, data):
crc = zlib.crc32(type + data) & 0xffffffff
return struct.pack(">L", len(data)) + type + data + struct.pack(">L", crc)
width = 2147483647
height = 69
segment_size = 1000000
segment_data = b"\x00" * segment_size * height
with open("widest_pink.png", "wb") as out:
out.write(b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")
out.write(create_chunk(b"IHDR", struct.pack(">LLBBBBB", width, height, 1, 3, 0, 0, 0)))
out.write(create_chunk(b"PLTE", b"\xFF\xC0\xCB"))
compressed_segment = zlib.compress(segment_data, level=zlib.Z_BEST_SPEED)
for i in range(width // segment_size):
if i % 10 == 0:
print(f"Written {i * segment_size} columns...")
out.write(create_chunk(b"IDAT", compressed_segment))
remainder = width % segment_size
if remainder:
compressed_remainder = zlib.compress(b"\x00" * remainder * height, level=zlib.Z_BEST_SPEED)
out.write(create_chunk(b"IDAT", compressed_remainder))
out.write(create_chunk(b"IEND", b""))
print("Image generation completed!")