From 90a21af1d3270accccc6c90ce0358e6cef3a7abd Mon Sep 17 00:00:00 2001 From: Iain Date: Mon, 16 Nov 2026 21:10:28 +0000 Subject: [PATCH] Embed local SVG images as image/svg+xml --- folium/utilities.py | 2 ++ tests/test_utilities.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/folium/utilities.py b/folium/utilities.py index af464900b0..123054206c 100644 --- a/folium/utilities.py +++ b/folium/utilities.py @@ -186,6 +186,8 @@ def image_to_url( """ if isinstance(image, str) and not _is_url(image): fileformat = os.path.splitext(image)[-1][1:] + if fileformat.lower() == "svg": + fileformat = "svg+xml" with open(image, "rb") as f: img = f.read() b64encoded = base64.b64encode(img).decode("utf-8") diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 74d95c763a..48d30df78c 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -265,6 +265,12 @@ def test_image_to_url_url(): assert image_to_url(url) == url +def test_image_to_url_svg(tmp_path): + path = tmp_path / "icon.svg" + path.write_text('') + assert image_to_url(str(path)).startswith("data:image/svg+xml;base64,") + + @pytest.mark.parametrize( "text,result", [