forked from tdamdouni/Pythonista
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-image-to-PIL.py
More file actions
36 lines (26 loc) · 806 Bytes
/
ui-image-to-PIL.py
File metadata and controls
36 lines (26 loc) · 806 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
def pil2ui(pil_img):
with io.BytesIO() as buffer:
pil_img.save(buffer, format='PNG')
return ui.Image.from_data(buffer.getvalue())
# other ideas... ==========================
import io
import ui
from PIL import Image, ImageOps, ImageFilter
def sketch(pil_img):
return ImageOps.grayscale(pil_img.filter(ImageFilter.CONTOUR))
def emboss(pil_img):
return ImageOps.grayscale(pil_img.filter(ImageFilter.EMBOSS))
def ui2pil(ui_img):
return Image.open(io.BytesIO(ui_img.to_png()))
def pil2ui(pil_img):
with io.BytesIO() as buffer:
pil_img.save(buffer, format='PNG')
return ui.Image.from_data(buffer.getvalue())
def main():
img = ui2pil(ui.Image.named('Dog_Face'))
sketch(img).show()
img1 = pil2ui(img)
img2 = ui2pil(img1)
emboss(img2).show()
if __name__ == '__main__':
main()