PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Writer\Exception
$bitmap: largest image height supported is 65k.\n
Error message
$bitmap: largest image height supported is 65k.\n
What it means
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.
Source
Thrown at src/PhpSpreadsheet/Writer/Xls/Worksheet.php:2510
$data = substr($data, 4);
$size -= 0x36; // Subtract size of bitmap header.
$size += 0x0C; // Add size of BIFF header.
// Remove bitmap data: reserved, offset, header length.
$data = substr($data, 12);
// Read and remove the bitmap width and height. Verify the sizes.
$width_and_height = unpack('V2', substr($data, 0, 8)) ?: [];
/** @var int */
$width = $width_and_height[1];
/** @var int */
$height = $width_and_height[2];
$data = substr($data, 8);
if ($width > 0xFFFF) {
throw new WriterException("$bitmap: largest image width supported is 65k.\n");
}
if ($height > 0xFFFF) {
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");View on GitHub (pinned to 65b080eef4)
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
Defensive patterns
Strategy: validation
Validate before calling
$fh = fopen($path, 'rb');
fseek($fh, 22); // biHeight at offset 22 in the info header
$height = unpack('V', (string) fread($fh, 4))[1];
fclose($fh);
if ($height > 0xFFFF) {
throw new RangeException("Bitmap height $height exceeds 65535; resize or use Xlsx + Drawing");
}
$worksheetWriter->insertBitmap($row, $col, $path); Prevention
- Cap both dimensions when preparing images for legacy Xls embedding
- Long screenshots/stitched images should go through the Xlsx writer
When it happens
Trigger: Calling insertBitmap() with a valid 24-bit BMP taller than 65,535 pixels.
Common situations: Long screenshots, full-page captures, or stitched images embedded into legacy .xls exports.
Related errors
- $bitmap: largest image width supported is 65k.\n
- Rows or columns overflow! Excel5 has limit to 65535 rows and
- Couldn't import $bitmap
- $bitmap doesn't contain enough data.\n
- $bitmap doesn't appear to be a valid bitmap image.\n
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/c7892cdd385509e8.
Report an issue: GitHub.