aboutsummaryrefslogtreecommitdiff
path: root/encode_picture.py
blob: 66b5ce12e549c80b45cf25b854b1ab2e4ea9c025 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import base64


def encode(path):
	filetype = path.split(".")[-1].lower()
	if filetype == "jpg": 
		filetype = "jpeg"
	elif filetype == "svg": 
		filetype = "svg+xml"
	with open(path, "rb") as file: 
		raw = file.read()
	encoded = base64.b64encode(raw).decode("utf-8", "surrogateescape")
	encoded = f"data:image/{filetype};base64," + encoded
	return encoded


if __name__ == "__main__":
	in_path = input()
	print(encode(in_path))