{
  "schemaVersion": "1.0",
  "canonicalPage": "https://fileformat.co/ext/png",
  "inspectorUrl": "https://fileformat.co/inspect",
  "spec": {
    "slug": "png",
    "extension": ".png",
    "aliases": [],
    "name": "Portable Network Graphics (PNG)",
    "shortName": "PNG",
    "category": "media-3d",
    "tier": 1,
    "summary": "Lossless CRC-checked chunked raster image format, heavily used in AI workflows (ComfyUI / Stable Diffusion) to store generation graphs and prompts inside `tEXt`/`iTXt` chunks.",
    "technicalNotes": "The 8-byte signature (`89 50 4E 47 0D 0A 1A 0A`) intentionally detects 7-bit ASCII stripping, CRLF<->LF line-ending conversion, and EOF truncation immediately.",
    "mimeTypes": [
      "image/png"
    ],
    "identifiers": {
      "pronomPuid": "fmt/11",
      "specUrl": "https://www.w3.org/TR/png-3/"
    },
    "binarySignature": {
      "endianness": "big",
      "magicBytes": [
        {
          "offset": 0,
          "hex": "89 50 4E 47 0D 0A 1A 0A",
          "ascii": ".PNG....",
          "description": "8-byte PNG transport-integrity signature"
        }
      ],
      "containerFamily": null,
      "headerLayout": [
        {
          "offset": "0x00 - 0x07",
          "byteOffset": 0,
          "byteLength": 8,
          "lengthLabel": "8 B",
          "dataType": "uint8[8]",
          "fieldName": "png_sig",
          "description": "89 50 4E 47 0D 0A 1A 0A"
        },
        {
          "offset": "0x08 - 0x0F",
          "byteOffset": 8,
          "byteLength": 8,
          "lengthLabel": "8 B",
          "dataType": "u32_be+char[4]",
          "fieldName": "ihdr_hdr",
          "description": "Length (13) + 'IHDR' chunk type"
        },
        {
          "offset": "0x10 - 0x17",
          "byteOffset": 16,
          "byteLength": 8,
          "lengthLabel": "8 B",
          "dataType": "uint32_be[2]",
          "fieldName": "dimensions",
          "description": "Width and Height in pixels"
        },
        {
          "offset": "0x18 - 0x1C",
          "byteOffset": 24,
          "byteLength": 5,
          "lengthLabel": "5 B",
          "dataType": "uint8[5]",
          "fieldName": "pixel_fmt",
          "description": "Bit depth, color type, compression, filter, interlace"
        }
      ]
    },
    "securityProfile": {
      "riskLevel": "low",
      "allowsArbitraryCodeOrMacros": false,
      "xxeRisk": false,
      "polyglotPrependRisk": false,
      "pickleDeserializationRisk": false,
      "uploadValidationNotes": "Check width * height <= max_pixels from bytes 0x10..0x17 BEFORE zlib decompression, and strip ancillary tEXt/iTXt/eXIf chunks to prevent metadata leaks (and Acropalypse-style trailing byte leaks after IEND)."
    },
    "codeSnippets": {
      "python": "import struct, sys\nwith open(sys.argv[1], \"rb\") as f:\n    sig, length, ctype, w, h, depth, color = struct.unpack(\">8sI4sIIBB\", f.read(26))\n    assert sig == b\"\\x89PNG\\r\\n\\x1a\\n\" and ctype == b\"IHDR\"\n    print(f\"PNG {w}x{h}px, {depth}-bit color_type={color}\")",
      "typescript": "export async function readPngDimensions(file: File) {\n  const dv = new DataView(await file.slice(0, 26).arrayBuffer());\n  return { width: dv.getUint32(16, false), height: dv.getUint32(20, false), bitDepth: dv.getUint8(24) };\n}",
      "rust": "use std::{fs::File, io::Read};\nfn main() -> std::io::Result<()> {\n    let mut b = [0u8; 24];\n    File::open(std::env::args().nth(1).expect(\"usage: <prog> <file>\"))?.read_exact(&mut b)?;\n    let w = u32::from_be_bytes(b[16..20].try_into().expect(\"fixed-size byte window\"));\n    let h = u32::from_be_bytes(b[20..24].try_into().expect(\"fixed-size byte window\"));\n    println!(\"PNG {w}x{h}\");\n    Ok(())\n}",
      "go": "package main\nimport (\"encoding/binary\"; \"fmt\"; \"io\"; \"os\")\nfunc main() {\n    f, err := os.Open(os.Args[1])\n    if err != nil {\n        fmt.Fprintln(os.Stderr, \"open:\", err)\n        os.Exit(1)\n    }\n    defer f.Close()\n    b := make([]byte, 24)\n    if _, err := io.ReadFull(f, b); err != nil {\n        fmt.Fprintln(os.Stderr, \"read:\", err)\n        os.Exit(1)\n    }\n    fmt.Printf(\"PNG %dx%d\\n\", binary.BigEndian.Uint32(b[16:20]), binary.BigEndian.Uint32(b[20:24]))\n}"
    },
    "relatedFormats": [
      "webp",
      "avif",
      "jpg"
    ],
    "verifiedAt": "2026-11-14T16:09:03Z"
  },
  "samples": [
    {
      "id": "png-minimal",
      "filename": "minimal-2x2-rgba.png",
      "variant": "minimal",
      "title": "Minimal Valid 2×2 RGBA PNG",
      "description": "Real 8-bit RGBA PNG encoded by Pillow with valid CRC32 checksums on every chunk.",
      "localPath": "/fixtures/v1/png/minimal-2x2-rgba.png",
      "cdnUrl": "https://fileformat.co/fixtures/v1/png/minimal-2x2-rgba.png",
      "sizeBytes": 83,
      "sha256": "275f56b84188ce563dfa9364ba7d2b3dfec7beb5d62de11bddcafb0390e85752",
      "expectValid": true
    },
    {
      "id": "png-realistic",
      "filename": "ai-prompt-metadata.png",
      "variant": "realistic",
      "title": "PNG with Embedded Stable Diffusion `parameters` tEXt Chunk",
      "description": "16×16 RGBA PNG from Pillow containing AI generation prompt metadata inside a standard tEXt chunk.",
      "localPath": "/fixtures/v1/png/ai-prompt-metadata.png",
      "cdnUrl": "https://fileformat.co/fixtures/v1/png/ai-prompt-metadata.png",
      "sizeBytes": 305,
      "sha256": "1c159eb8d483c4379933d83bac5ba8581b50e5651f9877c059e999cc102840de",
      "expectValid": true
    },
    {
      "id": "png-edge-case",
      "filename": "truncated-idat.png",
      "variant": "edge-case",
      "title": "Truncated PNG Mid-IDAT Stream",
      "description": "Real Pillow PNG truncated inside the compressed IDAT payload — decode must fail (missing IEND alone would still decode).",
      "localPath": "/fixtures/v1/png/truncated-idat.png",
      "cdnUrl": "https://fileformat.co/fixtures/v1/png/truncated-idat.png",
      "sizeBytes": 47,
      "sha256": "ac4cc6aeb4c37baeee650f26c1651411aaade073ecee5db776d40defcac6e53a",
      "expectValid": false,
      "edgeCaseTag": "Truncated IDAT Payload"
    }
  ]
}