Skip to content

fix: map image/bmp to Pillow's BMP format instead of DIB - #13743

Merged
anakin87 merged 2 commits into
deepset-ai:mainfrom
67-luck:fix/image-bmp-mime-format
Nov 20, 2026
Merged

anakin87 merged 2 commits into
deepset-ai:mainfrom
67-luck:fix/image-bmp-mime-format

Conversation

@67-luck

@67-luck 67-luck commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

MIME_TO_FORMAT (haystack/dataclasses/image_content.py) is built by inverting FORMAT_TO_MIME. Both "BMP" and "DIB" map to "image/bmp" there, and the later "DIB" entry wins, so image/bmp was mapped to Pillow's headerless DIB format. When size is set, _encode_image_to_base64 therefore:

  • opened image/bmp input with formats=["DIB"], which can't read a regular .bmp file, so ImageFileToImageContent and DocumentToImageContent logged a warning and dropped it;
  • re-encoded inferred-BMP input as "DIB", so the output didn't start with the BM header but was still labeled image/bmp.

The fix maps image/bmp back to "BMP" explicitly, next to the existing MIME_TO_FORMAT["image/jpg"] = "JPEG" override. IMAGE_MIME_TYPES is unchanged.

How did you test it?

  • New test TestEncodeImageToBase64::test_encode_image_to_base64_downsize_bmp, parametrized over mime_type="image/bmp" and None. Both cases fail on main (UnidentifiedImageError, and data starting with b'(\x00' instead of b'BM') and pass with this change.
  • test/components/converters/image/test_image_utils.py, test_file_to_image.py and test/dataclasses/test_image_content.py: 47 passed. The 8 failures there come from pypdfium2 not being installed locally and fail the same way on main.
  • Manually: the reproduction from Resizing BMP images fails: image/bmp is mapped to Pillow's headerless DIB format #13742 converts the resized .bmp file (0 → 1 result), and the re-encoded data starts with BM.
  • ruff check and ruff format --check pass.

Notes for the reviewer

Release note: releasenotes/notes/image-bmp-mime-format-3d8a1f6c2e9b4a70.yaml. I used Claude Code to prepare this change and reviewed and tested it myself.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@67-luck
67-luck requested a review from a team as a code owner November 14, 2026 02:33
@67-luck
67-luck requested review from anakin87 and removed request for a team November 14, 2026 02:33
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@67-luck is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/dataclasses
  image_content.py
Project Total  

This report was generated by python-coverage-comment-action

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I pushed a minor simplification.

@anakin87
anakin87 enabled auto-merge (squash) November 20, 2026 14:59
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Nov 20, 2026
@anakin87
anakin87 merged commit c1528ea into deepset-ai:main Nov 20, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resizing BMP images fails: image/bmp is mapped to Pillow's headerless DIB format

2 participants