Created
February 17, 2024 17:37
-
-
Save ghoshbishakh/f781c393a434451b8d5557370f04982d to your computer and use it in GitHub Desktop.
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 requests | |
import base64 | |
def download_and_convert_svg(url): | |
try: | |
# Download SVG image from the URL | |
response = requests.get(url) | |
response.raise_for_status() | |
# Convert the SVG content to base64 | |
svg_content = response.content | |
base64_encoded = base64.b64encode(svg_content).decode('utf-8') | |
# Create the HTML image tag with base64 encoded data | |
html_image_tag = f'<img src="data:image/svg+xml;base64,{base64_encoded}" />' | |
return html_image_tag | |
except requests.exceptions.RequestException as e: | |
print(f"Error: {e}") | |
return None | |
if __name__ == "__main__": | |
svg_url = input("Enter the SVG image URL: ") | |
html_image_tag = download_and_convert_svg(svg_url) | |
if html_image_tag: | |
print("HTML Image Tag:") | |
print(html_image_tag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment