PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Writer\Exception
$bitmap: compression not supported in bitmap image.\n
Error message
$bitmap: compression not supported in bitmap image.\n
What it means
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.
Source
Thrown at src/PhpSpreadsheet/Writer/Xls/Worksheet.php:2528
throw new WriterException("$bitmap: largest image height supported is 65k.\n");
}
// Read and remove the bitmap planes and bpp data. Verify them.
$planes_and_bitcount = unpack('v2', substr($data, 0, 4));
$data = substr($data, 4);
if ($planes_and_bitcount === false || $planes_and_bitcount[2] != 24) { // Bitcount
throw new WriterException("$bitmap isn't a 24bit true color bitmap.\n");
}
if ($planes_and_bitcount[1] != 1) {
throw new WriterException("$bitmap: only 1 plane supported in bitmap image.\n");
}
// Read and remove the bitmap compression. Verify compression.
$compression = unpack('Vcomp', substr($data, 0, 4));
$data = substr($data, 4);
if ($compression === false || $compression['comp'] != 0) {
throw new WriterException("$bitmap: compression not supported in bitmap image.\n");
}
// Remove bitmap data: data size, hres, vres, colours, imp. colours.
$data = substr($data, 20);
// Add the BITMAPCOREHEADER data
$header = pack('Vvvvv', 0x000C, $width, $height, 0x01, 0x18);
$data = $header . $data;
return [$width, $height, $size, $data];
}
/**
* Store the window zoom factor. This should be a reduced fraction but for
* simplicity we will store all fractions with a numerator of 100.
*/
private function writeZoom(): void
{View on GitHub (pinned to 65b080eef4)
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()
Defensive patterns
Strategy: validation
Validate before calling
$compression = unpack('V', (string) file_get_contents($path, false, null, 30, 4))[1];
if ($compression !== 0) {
// re-encode uncompressed via GD
$im = imagecreatefrombmp($path);
imagebmp($im, $path); // GD writes uncompressed 24-bit BMP
}
$worksheetWriter->insertBitmap($row, $col, $path); Prevention
- 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
When it happens
Trigger: insertBitmap() with an RLE-compressed BMP, commonly produced when saving 8-bit palette images with compression enabled.
Common situations: Disk-space-conscious legacy pipelines that RLE-compress BMPs; images processed through older Windows imaging APIs.
Related errors
- Couldn't import $bitmap
- $bitmap doesn't contain enough data.\n
- $bitmap isn't a 24bit true color bitmap.\n
- $bitmap doesn't appear to be a valid bitmap image.\n
- $bitmap: largest image width supported is 65k.\n
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/10620ae026895463.
Report an issue: GitHub.