python - 在 PPT 占位符中适合图片
问题描述
我想在 PPT 占位符中放置一张图片,并查看了以下两个链接:
从类似的问题,我已经应用了解决方案,但它仍然在 ppt 中显示裁剪图像。
我的代码相同:
prs = Presentation(path)
title_slide_layout = prs.slide_layouts[4] ## Changed the content to picture as I need two pictures in one slide
pic_placeholder = slide.placeholders[15] ## The two picture placeholders
pic_placeholder1 = slide.placeholders[16]
print(pic_placeholder.left.inches, pic_placeholder.top.inches, pic_placeholder.width.inches, pic_placeholder.height.inches)
## 0.5 2.4461811023622047 4.4184033245844265 4.253472222222222
"""Below solution from the question posted above """
pic_placeholder.left = Inches(0.1)
pic_placeholder.width = Inches(3)
pic_placeholder.height = Inches(3)
##Similarly I need to do for 2nd picture also, but it is not working for this picture also
prs.save(path)
至于Similar Query
链接,我无法理解,最终解决方案是什么,如何实现。
问题陈述:(你想达到什么目的?
想要在幻灯片中并排获得两个图像,它们应该适合占位符并保留纵横比
你尝试了什么?
上面的代码是我试过的!
它在哪些具体方面不起作用?
在实施该解决方案时,我仍然从一侧得到裁剪的图像。
我想要的只是一张幻灯片上的两张不同的图像,而且没有一张被裁剪!!
解决方案
图片占位符没有“缩小以适应”选项。无论您想对插入的图片进行何种额外调整,您都需要自己进行。
您没有显示用于插入图片的代码,因此我无法帮助您提供具体细节。但是,请注意返回的对象picture_placeholder.insert_picture()
不是对象picture_placeholder
本身。该对象在此过程中被删除(当您在那里执行此操作时,它在 PowerPoint 本身中)并被图片对象替换。因此,您对现在孤立的占位符元素所做的任何调整都将无效。你需要更多这样的东西:
inserted_picture = picture_placeholder.insert_picture(...)
inserted_picture.left = ...
inserted_picture.width = ...
推荐阅读
- python - 如何将“networkx.digraph”视为无向
- regex - 在 VScode 中查找和删除组标签
- python - 检查每个字母
- uwp - 为什么 Header 比 Title 大,什么时候使用?
- vulkan - Vulkan 队列提交同步 - vkWaitForFences vs vkQueueWaitIdle
- javascript - 无法在基于反应的应用程序上单击带有 selenium webdriver 的按钮
- python - session.add() 和会话方法不存在
- ios - SwiftUI:我想每天显示一个随机元素,即使在重新启动应用程序之后也是如此
- typescript - 类型“{}”上不存在属性“onMessage”。& “{}”类型的参数不能分配给“null”类型的参数
- mysql - 如果 Id,如何获取名称