python在RTF中嵌入图像



我有一个小Python程序,可以编辑RTF模板。我需要在rtf文件的特定位置嵌入广告图像

我发现了这段png图像的代码(最初我认为是在C#中(:

mpic = "{pictpngblippicw" + img_Width + "pich" + img_Height + "picwgoal" + width + @"pichgoal" + height + "bin " + str + "}"

我不知道哪个库可以让我将图像转换为正确的格式,有人能给我一些建议吗?

非常感谢,Willy

它有点复杂,但有效:D

...
filename = 'temp.png'
hex_content = ''
from PIL import Image
im = Image.open(filename)
width, height = im.size
im.close()
with open(filename, 'rb') as f:
content = f.read()
hex_content = binascii.hexlify(content)
f.close()
file_content = file_content.replace("<#LEAKS_IMAGE>",'{pictpngblippicw'+str(width)+'pich'+str(height)+'picwgoal10000pichgoal8341 '+hex_content+'}')
...

最新更新