{"record":{"id":"c7892cdd385509e8","repo":"PHPOffice/PhpSpreadsheet","slug":"bitmap-largest-image-height-supported-is-65k-n","errorCode":null,"errorMessage":"$bitmap: largest image height supported is 65k.\\n","messagePattern":"\\$bitmap: largest image height supported is 65k\\.\\\\n","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Writer\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Writer/Xls/Worksheet.php","lineNumber":2510,"sourceCode":"        $data = substr($data, 4);\n        $size -= 0x36; // Subtract size of bitmap header.\n        $size += 0x0C; // Add size of BIFF header.\n\n        // Remove bitmap data: reserved, offset, header length.\n        $data = substr($data, 12);\n\n        // Read and remove the bitmap width and height. Verify the sizes.\n        $width_and_height = unpack('V2', substr($data, 0, 8)) ?: [];\n        /** @var int */\n        $width = $width_and_height[1];\n        /** @var int */\n        $height = $width_and_height[2];\n        $data = substr($data, 8);\n        if ($width > 0xFFFF) {\n            throw new WriterException(\"$bitmap: largest image width supported is 65k.\\n\");\n        }\n        if ($height > 0xFFFF) {\n            throw new WriterException(\"$bitmap: largest image height supported is 65k.\\n\");\n        }\n\n        // Read and remove the bitmap planes and bpp data. Verify them.\n        $planes_and_bitcount = unpack('v2', substr($data, 0, 4));\n        $data = substr($data, 4);\n        if ($planes_and_bitcount === false || $planes_and_bitcount[2] != 24) { // Bitcount\n            throw new WriterException(\"$bitmap isn't a 24bit true color bitmap.\\n\");\n        }\n        if ($planes_and_bitcount[1] != 1) {\n            throw new WriterException(\"$bitmap: only 1 plane supported in bitmap image.\\n\");\n        }\n\n        // Read and remove the bitmap compression. Verify compression.\n        $compression = unpack('Vcomp', substr($data, 0, 4));\n        $data = substr($data, 4);\n\n        if ($compression === false || $compression['comp'] != 0) {\n            throw new WriterException(\"$bitmap: compression not supported in bitmap image.\\n\");","sourceCodeStart":2492,"sourceCodeEnd":2528,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Writer/Xls/Worksheet.php#L2492-L2528","documentation":"Companion to the width check: the BMP info header's height field must not exceed 0xFFFF (65,535 pixels) because the Xls IMDATA record stores it in 16 bits. processBitmap() throws during header validation before any pixel data is converted.","triggerScenarios":"Calling insertBitmap() with a valid 24-bit BMP taller than 65,535 pixels.","commonSituations":"Long screenshots, full-page captures, or stitched images embedded into legacy .xls exports.","solutions":["Resize/crop the image so height is at most 65,535 px","Export as Xlsx and use the Drawing API for large images","Downscale via GD/Imagick before insertion"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"$fh = fopen($path, 'rb');\nfseek($fh, 22); // biHeight at offset 22 in the info header\n$height = unpack('V', (string) fread($fh, 4))[1];\nfclose($fh);\n\nif ($height > 0xFFFF) {\n    throw new RangeException(\"Bitmap height $height exceeds 65535; resize or use Xlsx + Drawing\");\n}\n$worksheetWriter->insertBitmap($row, $col, $path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap both dimensions when preparing images for legacy Xls embedding","Long screenshots/stitched images should go through the Xlsx writer"],"tags":["phpspreadsheet","xls","bitmap","image-size","limits"],"backgroundTag":"image-dimension-limit-exceeded","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}