Created
December 16, 2024 23:26
-
-
Save moritztim/a981e4df8a3a61cdcd1a173bdf842a1c to your computer and use it in GitHub Desktop.
Text to Data URL in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
def data_url(mime_sub_type: str, text: str) -> str: | |
"""Convert text to data URL""" | |
return f"data:text/{mime_sub_type};base64,{base64.b64encode(text.encode()).decode()}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment