0

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!!

Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51
  • 1
    Please state your question clearly. Don't ask us to form it from some operation on two other questions. What do you want to achieve? What did you try? In what specific ways did it not work? – scanny Jun 26 '19 at 16:14
  • @scanny: Updated the question!! Let me know if it is still unclear!! – Rahul Agarwal Jun 26 '19 at 18:22
  • 1
    Can you include an example screenshot? You say "in the placeholder", is it one or two placeholders? Does the same thing happen with just one placeholder? If so let's reduce question to one to make it similar. How do you want to deal with a size difference? shrink to fit or resize placeholder? – scanny Jun 27 '19 at 16:17
  • There are two placeholders in my slide...and both of them have to have one picture. This issue is with both the placeholders. I have done resizing of placeholder but it is still not working.the image is still getting cropped. I would like `shrink to fit` option!! – Rahul Agarwal Jun 27 '19 at 17:57
  • 1
    Ah, okay. Now I see. – scanny Jun 27 '19 at 18:00

1 Answers1

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 = ...
scanny
  • 26,423
  • 5
  • 54
  • 80
  • You might also be interested in the answer to this other question that came in the day after yours: https://stackoverflow.com/questions/56815178/how-can-i-get-the-dimensions-of-a-picture-placeholder-to-re-size-an-image-when-c/56820677?noredirect=1#comment100197169_56820677 – scanny Jun 30 '19 at 19:17