diff options
Diffstat (limited to 'mammoth/images.py')
| -rw-r--r-- | mammoth/images.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mammoth/images.py b/mammoth/images.py index 297b0a2..9dba353 100644 --- a/mammoth/images.py +++ b/mammoth/images.py @@ -1,3 +1,5 @@ +import base64 + from . import html @@ -13,3 +15,13 @@ def img_element(func): # Undocumented, but retained for backwards-compatibility with 0.3.x inline = img_element + + +@img_element +def data_uri(image): + with image.open() as image_bytes: + encoded_src = base64.b64encode(image_bytes.read()).decode("ascii") + + return { + "src": "data:{0};base64,{1}".format(image.content_type, encoded_src) + } |
