Help Center/ Optical Character Recognition/ FAQs/ API/ How Do I Obtain the Base64 Code of an Image?
Updated on 2023-12-29 GMT+08:00

How Do I Obtain the Base64 Code of an Image?

An image needs to be converted to its Base64 code for recognition. This section uses Python as an example to describe how to convert a local image to the Base64 code. 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)