import os
import re
file = r'k8s.md'
new_file = 'new_'+file
pattern = re.compile(r"(\s*)!\[\]\((https://.*png)\)")
with open(file, 'r', encoding='utf-8') as f, open(new_file, 'w+', encoding='utf-8') as w:
for line in f.readlines():
res = pattern.search(line)
if res:
print(line)
# print(res.group(2))
line = res.group(1) + r'<img src="'+res.group(2)+r'" width="50%" height="50%" />' + '\n' #设置缩放比例
print(line)
w.write(line)
print('完成')
缩放前:
缩放后
标签:缩放,res,博客园,file,print,new,line,图片 From: https://www.cnblogs.com/areke/p/16628928.html