python - python在RTF中嵌入图像
问题描述
我有一个编辑 RTF 模板的小型 Python 程序。我需要在 rtf 文件的特定位置嵌入广告图片
我找到了 png 图像的这段代码(最初我认为是在 C# 中):
mpic = "{\pict\pngblip\picw" + img_Width + "\pich" + img_Height + "\picwgoal" + width + @"\pichgoal" + height + "\bin " + str + "}"
我不知道哪个库可以让我将图像转换为正确的格式,有人可以给我一些提示吗?
非常感谢,威利
解决方案
这有点复杂但有效: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>",'{\pict\pngblip\picw'+str(width)+'\pich'+str(height)+'\picwgoal10000\pichgoal8341 '+hex_content+'}')
...
推荐阅读
- java - 来自 jsp 输入表单的错误编码
- html - 将图像的显示类型更改为“块”,使其下角变圆,如何?
- python - 如何随机化两次,而第二次与第一次不相交
- jmeter-plugins - 如何在没有互联网连接的 Windows 10 机器上安装 Taurus 框架?
- vue.js - 在 vuejs 中管理大型计算对象
- python - Flask 仅在 post api 获取数据时渲染 html
- javascript - 角度打印过滤列表
- glsl - glsl 将 mat2x4 重新解释为 mat4x2
- python - 使用顺序模型预测()方法的正确方法
- powershell - Windows 11 Cascade Windows:可以使用 AutoHotkey,而不是 VBScript 或 PowerShell