5. Create a transparent 1×1 PNG

The PNG model works at the wire-format layer. Supply an RGBA IHDR, one transparent pixel in the IDAT scanline, and an IEND chunk. The IDAT payload is compressed with zlib because PNG image decompression is intentionally outside the schema model:

import zlib

from rustruct.formats.image.png import Chunk, ChunkType, ColorType, IHDR, PNG


transparent_scanline = zlib.compress(b"\x00\x00\x00\x00\x00")
image = PNG(
    chunks=[
        Chunk(
            type=ChunkType.IHDR,
            data=IHDR(width=1, height=1, bit_depth=8, color_type=ColorType.RGBA),
        ),
        Chunk(type=ChunkType.IDAT, data=transparent_scanline),
        Chunk(type=ChunkType.IEND, data=b""),
    ]
)
wire = image.pack()
decoded = PNG.unpack(wire)

assert decoded.chunks[0].data.width == 1
assert decoded.chunks[0].data.height == 1
assert decoded.chunks[0].data.color_type == ColorType.RGBA
assert decoded.chunks[1].type == ChunkType.IDAT
assert decoded.pack() == wire

The first scanline byte is the PNG filter byte (0); the following four zero bytes are the transparent RGBA pixel. rustruct.Struct.pack() derives each length and CRC-32, and rustruct.Struct.unpack() verifies them on the way back.

Previous: 4. Create a minimal PNG container.

You have used the same typed workflow across a network packet, a pointer-oriented protocol, and a chunked file format. The focused how-to guides start at How to use the IPv4 model, How to use the DNS model, and How to build and decode PNG files; the complete class listings are in Protocol and format API.