Help Center/ Face Recognition Service/ FAQs/ APIs/ How Do I Obtain the Base64 Code of an Image?
Updated on 2023-10-19 GMT+08:00

How Do I Obtain the Base64 Code of an Image?

This section uses Python as an example to describe how to convert a local image into Base64 encoding. You can also use an online conversion tool.

Replace d:\demo.jpg in the code with the actual image path.

import base64
with open("d:\demo.jpg", "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read()).decode()
print(encoded_string)