Answers for "how to convert images to base64 in python and then decode it as a link"

7

python convert image to base64

import base64

file = 'deer.jpg'
image = open(file, 'rb')
image_read = image.read()
image_64_encode = base64.encodebytes(image_read) #encodestring also works aswell as decodestring

print('This is the image in base64: ' + str(image_64_encode))

image_64_decode = base64.decodebytes(image_64_encode) 
image_result = open('deer_decode.jpg', 'wb') # create a writable image and write the decoding result
image_result.write(image_64_decode)
Posted by: Guest on July-24-2020
0

convert url to base64 image py

import base64
import requests


def get_as_base64(url):

    return base64.b64encode(requests.get(url).content)
Posted by: Guest on November-22-2020

Code answers related to "how to convert images to base64 in python and then decode it as a link"

Python Answers by Framework

Browse Popular Code Answers by Language