RanjithkumarPanjabikesan commited on
Commit
f8bab5c
·
verified ·
1 Parent(s): 095a7fc

Create helper.py

Browse files
Files changed (1) hide show
  1. helper.py +14 -0
helper.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ from PIL import Image
3
+ import base64
4
+ #Define the Functions
5
+ def image_to_base64_str(pil_image):
6
+ byte_arr = io.BytesIO()
7
+ pil_image.save(byte_arr, format='PNG')
8
+ byte_arr = byte_arr.getvalue()
9
+ return str(base64.b64encode(byte_arr).decode('utf-8'))
10
+ def base64_to_pil(img_base64):
11
+ base64_decoded = base64.b64decode(img_base64)
12
+ byte_stream = io.BytesIO(base64_decoded)
13
+ pil_image = Image.open(byte_stream)
14
+ return pil_image