#如何利用python-docx-0.8.11 把插入到Word文档中的JPG,PNG图片设置图形样式,例如棱台形椭圆,柔化边缘矩形等
from docx import Document
from docx.shared import Inches
from docx.enum.dml import MSO_SHAPE, MSO_SHAPE_TYPE
document = Document()
# 添加一个图片
picture = document.add_picture('picture.png', width=Inches(2), height=Inches(2))
# 获取图片的形状对象
shape = picture.inline_shapes[0]
# 将形状设置为椭圆
shape_type = MSO_SHAPE.OVAL
shape_type_id = MSO_SHAPE_TYPE(shape_type)
shape._element.get_or_add_nvSpPr().get_or_add_cNvPr().set('descr', shape_type)
sp = shape._element.get_or_add_spPr()
sp.get_or_add_prstGeom().set('prst', shape_type_id)
document.save('document.docx')