-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_resize.py
52 lines (33 loc) · 1.09 KB
/
image_resize.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# %%
from PIL import Image
import io, base64
import traceback
# def resize_image(path, size, output_path):
# image = Image.open(path)
# image = image.resize(size,Image.ANTIALIAS)
# image.save(fp=output_path)
# path = "gui/assembly_pictures/"
# output_path = path
# output_name = lambda i: f"step_{i}_resize.png"
# for i in range(1,4):
# pic = path + f"step{i}.png"
# output_path = path + output_name(i)
# resize_image(pic, (300,300), output_path)
def resize_bin_output(path, size):
try:
image = Image.open(path)
image = image.resize(size, Image.Resampling.LANCZOS)
output = io.BytesIO()
image.save(output, format="PNG")
return base64.b64encode(output.getvalue())
except AttributeError as e:
print("*"*10, "Error while resizing image at: ", str(path))
print(e)
print(traceback.format_exc())
return None
except Exception as e:
print(e)
print(traceback.format_exc())
return None
p = "gui/assembly_pictures/cable_connected.png"
str(resize_bin_output(p, (300,300)))