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

Function main

utils/marker.py:168–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

166
167
168def main():
169 parse = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
170 parse.add_argument("-f", "--file", type=str, default="./input",
171 help="image file path or directory")
172 parse.add_argument("-m", "--mark", type=str, default="测试一句话行不行", help="watermark content")
173 parse.add_argument("-o", "--out", default="./2",
174 help="image output directory, default is ./output")
175 parse.add_argument("-c", "--color", default="#8B8B1B", type=str,
176 help="text color like '#000000', default is #8B8B1B")
177 parse.add_argument("-s", "--space", default=75, type=int,
178 help="space between watermarks, default is 75")
179 parse.add_argument("-a", "--angle", default=90, type=int,
180 help="rotate angle of watermarks, default is 30")
181 parse.add_argument("--font-family", default="./font/青鸟华光简琥珀.ttf", type=str,
182 help=textwrap.dedent('''\
183 font family of text, default is './font/青鸟华光简琥珀.ttf'
184 using font in system just by font file name
185 for example 'PingFang.ttc', which is default installed on macOS
186 '''))
187 parse.add_argument("--font-height-crop", default="1.2", type=str,
188 help=textwrap.dedent('''\
189 change watermark font height crop
190 float will be parsed to factor; int will be parsed to value
191 default is '1.2', meaning 1.2 times font size
192 this useful with CJK font, because line height may be higher than size
193 '''))
194 parse.add_argument("--size", default=50, type=int,
195 help="font size of text, default is 50")
196 parse.add_argument("--opacity", default=0.15, type=float,
197 help="opacity of watermarks, default is 0.15")
198 parse.add_argument("--quality", default=100, type=int,
199 help="quality of output images, default is 90")
200
201 args = parse.parse_args()
202
203 # 随机参数,从[A,B]中随机选取一个整数
204 space_ = [30, 40]
205 angel_ = [0, 180]
206 size_ = [20, 60]
207 opacity_ = [50, 95]
208 # 字体随机(需要别的字体的话,可以去字体网站下载)
209 fonts = [r'./font/青鸟华光简琥珀.ttf', r'./font/楷体_GB2312.ttf', './font/方正仿宋_GBK.TTF', './font/times.ttf',
210 './font/simhei.ttf']
211 if isinstance(args.mark, str) and sys.version_info[0] < 3:
212 args.mark = args.mark.decode("utf-8")
213
214 if os.path.isdir(args.file):
215 names = os.listdir(args.file)
216 for name in names:
217 image_file = os.path.join(args.file, name)
218 space = random.randint(space_[0], space_[1])
219 args.space = space
220 angel = random.randint(angel_[0], angel_[1])
221 args.angle = angel
222 size = random.randint(size_[0], size_[1])
223 args.size = size
224 opacity = random.randint(opacity_[0], opacity_[1]) / 100
225 args.opacity = opacity

Callers 1

marker.pyFile · 0.70

Calls 4

randomcolorFunction · 0.85
randomtextFunction · 0.85
gen_markFunction · 0.85
add_markFunction · 0.85

Tested by

no test coverage detected