Images are the important part of web applications.
Which are heavily used in some major application and ,some of the best applications are made on the base of the images.
Lets learn how to change the image from an URL to be converted to base64 encoded string which can be used directly to the img tag under html.
Lets see the code in python to do the same.
Which are heavily used in some major application and ,some of the best applications are made on the base of the images.
Lets learn how to change the image from an URL to be converted to base64 encoded string which can be used directly to the img tag under html.
Lets see the code in python to do the same.
import base64Now you have the string inside variable called converted data, which holds base64 encoded string for the image mentioned in the url variable.
import requests
url = "http://images.freeimages.com/images/previews/118/bicycle-sign-3-1442216.jpg"
response = requests.get(url)
convertedData = ("data:" + response.headers['Content-Type'] + ";" + "base64," +str(base64.b64encode(response.content).decode("utf-8")))
print convertedData