问题
I want to fit an image in PPT placeholder and looked two below links:
Similar Question
Similar Query
From the similar question, I have applied the solution but it is still showing cropped image in the ppt.
My code for the same:
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)
As for the Similar Query
link, I was not able to understand, what was the final solution, how can this be achieved.
Problem Statement: (What do you want to achieve?
Want to get two images side by side in a slide and they should fit in the placeholder and the aspect ratio is preserved
What did you try?
Above code is what I tried !!
In what specific ways did it not work?
When implementing the solution, I am still getting cropped images from one side.
All I want is two different images on one slide and none of them being cropped!!
回答1:
There is no "shrink-to-fit" option for a picture placeholder. Whatever additional adjustments you want to do to the inserted picture you will need to do yourself.
You have not shown the code you use for inserting the picture, so I can't help you with specifics there. However, do note that the object returned from picture_placeholder.insert_picture()
is not the picture_placeholder
object itself. That object is removed in the process (as it is in PowerPoint itself when you perform this operation there) and replaced by a picture object. So any adjustments you make on the now-orphaned placeholder element will have no effect. You need something more like this:
inserted_picture = picture_placeholder.insert_picture(...)
inserted_picture.left = ...
inserted_picture.width = ...
来源:https://stackoverflow.com/questions/56757127/fit-a-picture-in-ppt-placeholder