-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimageManager.py
More file actions
35 lines (24 loc) · 914 Bytes
/
Copy pathimageManager.py
File metadata and controls
35 lines (24 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import PySimpleGUI as sg
from PIL import Image
import requests
from io import BytesIO
class ImageManager:
def __init__(self) -> None:
pass
# Code to convert a URL to image data was taken form this help tread: https://github.com/PySimpleGUI/PySimpleGUI/issues/2941
def image_to_data(im):
with BytesIO() as output:
im.save(output, format="PNG")
data = output.getvalue()
return data
# Creates an image element from url
def create_image(url, resize, key = None):
response = requests.get(url, stream=True)
response.raw.decode_content = True
img = Image.open(response.raw)
data = ImageManager.image_to_data(img)
if(key != None):
img_box = sg.Image(data=data, key = key, enable_events=True)
else:
img_box = sg.Image(data=data, enable_events=True)
return img_box