PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Writer\Exception
$bitmap: largest image width supported is 65k.\n
Error message
$bitmap: largest image width supported is 65k.\n
What it means
While parsing the BMP info header, processBitmap() reads the width field and rejects values above 0xFFFF (65,535 pixels). The BIFF8 IMDATA record stores dimensions in 16-bit fields, so wider images cannot be represented in the .xls output this code path builds.
Source
Thrown at src/PhpSpreadsheet/Writer/Xls/Worksheet.php:2507
$size_array = unpack('Vsa', substr($data, 0, 4)) ?: [];
/** @var int */
$size = $size_array['sa'];
$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);View on GitHub (pinned to 65b080eef4)
Solutions
- Resize the image so width and height are both at most 65,535 px
- Export as Xlsx and attach the image through the Drawing API, which has no such limit
- Scale down via GD/Imagick before calling insertBitmap()
Defensive patterns
Strategy: validation
Validate before calling
$fh = fopen($path, 'rb');
fseek($fh, 18); // biWidth at offset 18 in the info header
$width = unpack('V', (string) fread($fh, 4))[1];
fclose($fh);
if ($width > 0xFFFF) {
$im = imagecreatefrombmp($path);
imagescale($im, 65535, (int) (imagesy($im) * 65535 / $width));
imagebmp($im, $path); // overwrite with resized 24-bit BMP
}
$worksheetWriter->insertBitmap($row, $col, $path); Prevention
- Downscale images to sane display size before embedding - Xls cells render them small anyway
- For images above 65k px, use the Xlsx writer + Drawing
When it happens
Trigger: Calling insertBitmap() with a valid 24-bit BMP whose pixel width exceeds 65,535 (e.g. large panoramas or print-resolution images).
Common situations: High-resolution source photos fed directly into legacy Xls embedding; automated pipelines that never downscale images.
Related errors
- $bitmap: largest image height 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/8f442cf18a10af69.
Report an issue: GitHub.