欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python利用pptx操作PPT實(shí)現(xiàn)幻燈片的刪除與替換

 更新時(shí)間:2023年02月03日 08:51:12   作者:虛壞叔叔  
這篇文章主要為大家詳細(xì)介紹了python如何使用pptx庫實(shí)現(xiàn)操作PPTx幻燈片文件刪除并替換圖片,文中的示例代碼講解詳細(xì),感興趣的可以嘗試一下

一、原理

通過查找ppt中的圖片指紋替換

二、操作流程

原始ppt如下:

根據(jù)oldpic.png的md5指紋 找到圖片

if md5img == md5finger:                   
                    slide.shapes.add_picture(newpic, shape.left, shape.top, shape.width, shape.height)
                    e.getparent().remove(e)

oldpic.png

想要替換的newpic.png

最后生成的成果如下:

三、代碼

完整代碼如下:

def replace_pic4shapes(filename, newpic, oldpic):
    # 把舊樣本圖片Logo,獲取指紋
    imageFile = open(oldpic, "rb")
    imgBlob = imageFile.read()
    md5finger = hashlib.md5(imgBlob).hexdigest()
    prs = Presentation(filename)
 
    for slide in list(prs.slides)[0:]:
        for shape in list(slide.shapes):
            ispicture= False
            try:
                md5img = hashlib.md5(shape.image.blob).hexdigest()
                ispicture = True
            except:
                pass
            e = shape.element
            if ispicture:
                if md5img == md5finger:                   
                    slide.shapes.add_picture(newpic, shape.left, shape.top, shape.width, shape.height)
                    e.getparent().remove(e)
                pass
 
    prs.save("課件工坊-長征組歌新文件.pptx")

到此這篇關(guān)于Python利用pptx操作PPT實(shí)現(xiàn)幻燈片的刪除與替換的文章就介紹到這了,更多相關(guān)Python PPT幻燈片刪除替換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論