Last active
May 26, 2019 11:50
-
-
Save Akronix/3e51fc248f8749eb0d4ad223181ef209 to your computer and use it in GitHub Desktop.
A very simple script to get the b64 code for a png image from a given URL.
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
get_b64_png.py | |
Descp: A very simple script to get the b64 code for a png image from a given | |
URL. | |
Created on: 26-may-2019 | |
Copyright 2019 Abel 'Akronix' Serrano Juste <[email protected]> | |
LICENSE: GPLv3.0 | |
""" | |
import sys | |
import requests | |
import base64 | |
def get_png_from_url(img_url): | |
img_res = requests.get(img_url, stream=True) | |
status_code = img_res.status_code | |
if status_code == 200: | |
b64 = base64.encodebytes(img_res.content) | |
return "data:image/png;base64,{}".format(str(b64, encoding='utf-8')) | |
def main(): | |
string = get_png_from_url(sys.argv[1]) | |
print('This is the b64 code:') | |
print(string) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment