From 4699776a6e2f1a07cb12360c716e42b6a1dbfad7 Mon Sep 17 00:00:00 2001 From: uditDewan Date: Wed, 15 Jul 2026 01:12:47 -0400 Subject: [PATCH] feat: add GIF support to ImageConverter (fixes #1103) --- .../markitdown/converters/_image_converter.py | 3 ++- packages/markitdown/tests/test_files/test.gif | Bin 0 -> 43 bytes packages/markitdown/tests/test_module_misc.py | 20 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/markitdown/tests/test_files/test.gif diff --git a/packages/markitdown/src/markitdown/converters/_image_converter.py b/packages/markitdown/src/markitdown/converters/_image_converter.py index dd8fbac61..988e82381 100644 --- a/packages/markitdown/src/markitdown/converters/_image_converter.py +++ b/packages/markitdown/src/markitdown/converters/_image_converter.py @@ -6,11 +6,12 @@ from .._stream_info import StreamInfo ACCEPTED_MIME_TYPE_PREFIXES = [ + "image/gif", "image/jpeg", "image/png", ] -ACCEPTED_FILE_EXTENSIONS = [".jpg", ".jpeg", ".png"] +ACCEPTED_FILE_EXTENSIONS = [".gif", ".jpg", ".jpeg", ".png"] class ImageConverter(DocumentConverter): diff --git a/packages/markitdown/tests/test_files/test.gif b/packages/markitdown/tests/test_files/test.gif new file mode 100644 index 0000000000000000000000000000000000000000..021fa1ab1f028a093cee1f9314be0acc40bef672 GIT binary patch literal 43 qcmZ?wbhEHbWMp7uXkcLY4@Cd}EB<6*00A8k0g_>0Vsc?*um%9#fCu*g literal 0 HcmV?d00001 diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py index 4d62e4919..253a8c431 100644 --- a/packages/markitdown/tests/test_module_misc.py +++ b/packages/markitdown/tests/test_module_misc.py @@ -506,6 +506,26 @@ def test_markitdown_llm_parameters() -> None: assert messages[0]["content"][0]["text"] == test_prompt +def test_markitdown_gif_image() -> None: + """Test that GIF images are accepted by the ImageConverter (issue #1103).""" + mock_client = MagicMock() + mock_response = MagicMock() + mock_response.choices = [MagicMock(message=MagicMock(content="A red pixel."))] + mock_client.chat.completions.create.return_value = mock_response + + markitdown = MarkItDown(llm_client=mock_client, llm_model="gpt-4o") + + # Must not raise UnsupportedFormatException + result = markitdown.convert(os.path.join(TEST_FILES_DIR, "test.gif")) + assert "A red pixel." in result.text_content + + # The image must be sent to the LLM with the correct content type + call_args = mock_client.chat.completions.create.call_args + messages = call_args[1]["messages"] + image_url = messages[0]["content"][1]["image_url"]["url"] + assert image_url.startswith("data:image/gif;base64,") + + @pytest.mark.skipif( skip_llm, reason="do not run llm tests without a key",