-
Notifications
You must be signed in to change notification settings - Fork 0
/
pilTutorial.py
131 lines (92 loc) · 3.23 KB
/
pilTutorial.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from PIL import Image, ImageDraw, ImageFont
import numpy as np
from mainOOP import Reader_bot
"""
PIL library discovering
____________________________________________________
Open an image
1 way: 2 way:
open: cv2 open: Image
transform to array: Image transform to array: nuPy
res: PIL obj res: PIL obj
____________________________________________________
#---text opacity in PIL---
image = Image.open(r'BACKs\good\bcInt.png').convert("RGBA")
w, h = np.size(image)
w *= 2
h *= 2
image = image.resize((w, h))
txt = Image.new("RGBA", (w, h), (0, 0, 0, 0))
tool = ImageDraw.Draw(txt)
font = ImageFont.truetype(r"D:\PYTHON\fineReader_bot\FONTS\Abram Font4You.ttf", size=50)
y = 0
for line in book_text:
tool.multiline_text((192, y_pos[y]), line, fill="#132C7D", font=font)
y += 1
out = Image.alpha_composite(image, txt)
out.show()
#sample = Image.fromarray(cv2.imread('BACKs/background.jpg'))
""" """
def put_point(img, x, y):
""" """
:param img: a picture in massive type
:param x: horizontal dimension
:param y: vertical dimension
:return: the image with drawn point
""" """
draw = ImageDraw.Draw(img)
draw.point((x, y), fill='red')
# img = np.asarray(img)
return img
def put_text(img, txt):
font = ImageFont.truetype("FONTS/Abram Font4You.ttf", size=80)
y_pos = 80
draw = ImageDraw.Draw(img)
draw.text((70, y_pos), txt, fill='rgb(0, 0, 0)', font=font)
return img
def put_text1(backImg: np.array, txt: list, font: int, color: str, size=50, paper="BACKs\\good\\bcInt.png"):
""" """
puts handwriting text on paper
** default text font is in Russian
:param backImg: background image
:param txt: notes text
:param font: handwriting font
:return: PIL instance - image with handwriting text on it
""" """
backImg = cv2.imread(paper)
image = Image.fromarray(backImg).convert("RGBA")
w, h = np.size(image)
w *= 2
h *= 2
image = image.resize((w, h))
for_txt = Image.new("RGBA", (w, h), (0, 0, 0, 0))
tool = ImageDraw.Draw(for_txt)
font = ImageFont.truetype("FONTS\\" + fonts[font] + " Font4You.ttf", size=size)
y = 0
for line in txt:
tool.multiline_text((192, y_pos[y]), line, fill=colors_rgb[color], font=font)
y += 1
out = Image.alpha_composite(image, for_txt)
return out
sample = Image.open(r"C:/Users\Anya\Pictures\PzpgoPqy-eM.jpg")
res = sample.crop((300, 70, 500, 200)) # x,y - the lefty uppermost coordinate
# x1, y1 - the rightly lowest coordinate
res.show()
""" """
x,y+ _ _ _ _ _
| |
| |
| _ _ _ _ + x1, y1
""" """
box = (300, 70, 500, 200)
res = sample.crop(box).transpose(Image.ROTATE_180)
sample.paste(res, box)
sample.show()
new_sample = sample.resize((1280, 640))
new_sample.show()
sample.rotate(91).show()
"""
def check(pipcture_arg):
print(pipcture_arg)
res = Image.open(pipcture_arg).convert('L')
res.show()