{"record":{"id":"10620ae026895463","repo":"PHPOffice/PhpSpreadsheet","slug":"bitmap-compression-not-supported-in-bitmap-image","errorCode":null,"errorMessage":"$bitmap: compression not supported in bitmap image.\\n","messagePattern":"\\$bitmap: compression not supported in bitmap image\\.\\\\n","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Writer\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Writer/Xls/Worksheet.php","lineNumber":2528,"sourceCode":"            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\");\n        }\n\n        // Remove bitmap data: data size, hres, vres, colours, imp. colours.\n        $data = substr($data, 20);\n\n        // Add the BITMAPCOREHEADER data\n        $header = pack('Vvvvv', 0x000C, $width, $height, 0x01, 0x18);\n        $data = $header . $data;\n\n        return [$width, $height, $size, $data];\n    }\n\n    /**\n     * Store the window zoom factor. This should be a reduced fraction but for\n     * simplicity we will store all fractions with a numerator of 100.\n     */\n    private function writeZoom(): void\n    {","sourceCodeStart":2510,"sourceCodeEnd":2546,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Writer/Xls/Worksheet.php#L2510-L2546","documentation":"processBitmap() reads the BMP compression field and requires 0 (BI_RGB, uncompressed). RLE-compressed 4/8-bit BMPs (BI_RLE8/BI_RLE4) and any other codec are rejected because the Xls IMDATA record can only store raw pixel bytes.","triggerScenarios":"insertBitmap() with an RLE-compressed BMP, commonly produced when saving 8-bit palette images with compression enabled.","commonSituations":"Disk-space-conscious legacy pipelines that RLE-compress BMPs; images processed through older Windows imaging APIs.","solutions":["Re-save the image as an uncompressed 24-bit BMP","Convert to PNG (compressed but supported) and use the Drawing API","Check the compression field before calling insertBitmap()"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"$compression = unpack('V', (string) file_get_contents($path, false, null, 30, 4))[1];\nif ($compression !== 0) {\n    // re-encode uncompressed via GD\n    $im = imagecreatefrombmp($path);\n    imagebmp($im, $path); // GD writes uncompressed 24-bit BMP\n}\n$worksheetWriter->insertBitmap($row, $col, $path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat RLE-compressed BMPs as invalid input; re-encode before embedding","Standardize intake on PNG and convert to BMP only at the last step, uncompressed"],"tags":["phpspreadsheet","xls","bitmap","compression","image"],"backgroundTag":"unsupported-image-compression","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}