MCPcopy Create free account
hub / github.com/Royalvice/DocDiff / mark_im

Function mark_im

utils/marker.py:125–163  ·  view source on GitHub ↗

在im图片上添加水印 im为打开的原图

(im)

Source from the content-addressed store, hash-verified

123 set_opacity(mark, args.opacity)
124
125 def mark_im(im):
126 """ 在im图片上添加水印 im为打开的原图"""
127
128 # 计算斜边长度
129 c = int(math.sqrt(im.size[0] * im.size[0] + im.size[1] * im.size[1]))
130
131 # 以斜边长度为宽高创建大图(旋转后大图才足以覆盖原图)
132 mark2 = Image.new(mode='RGBA', size=(c, c))
133
134 # 在大图上生成水印文字,此处mark为上面生成的水印图片
135 y, idx = 0, 0
136 while y < c:
137 # 制造x坐标错位
138 x = -int((mark.size[0] + args.space) * 0.5 * idx)
139 idx = (idx + 1) % 2
140
141 while x < c:
142 # 在该位置粘贴mark水印图片
143 mark2.paste(mark, (x, y))
144 x = x + mark.size[0] + args.space
145 y = y + mark.size[1] + args.space
146
147 # 将大图旋转一定角度
148 mark2 = mark2.rotate(args.angle)
149
150 # 在原图上添加大图水印
151 if im.mode != 'RGBA':
152 im = im.convert('RGBA')
153 mask = np.zeros_like(np.array(im))
154 mask = Image.fromarray(mask)
155 im.paste(mark2, # 大图
156 (int((im.size[0] - c) / 2), int((im.size[1] - c) / 2)), # 坐标
157 mask=mark2.split()[3])
158 mask.paste(mark2, # 大图
159 (int((im.size[0] - c) / 2), int((im.size[1] - c) / 2)), # 坐标
160 mask=mark2.split()[3])
161 #mask.show()
162 del mark2
163 return im, mask
164
165 return mark_im
166

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected