0

I want to insert pictures in a Picture Placeholder. Previously I get EXIF information to rotate if needed. This is my code:

placeholder = slide.placeholder[N]
photo.open()
ph_picture = placeholder.insert_picture(photo)
if exif['Orientation'] == LANDSCAPE_ORIENTATION:
    ph_picture.rotation = 90.0

When I open the pptx generated file in LibreOffice, the images looks great. But in PowerPoint they vanish. Removing the lines that rotates the image makes that the images appears again.

Any clue what is happening or what is a better way to rotate the images? (I've also tried with PIL but the result is even worst).

danieltellez
  • 206
  • 1
  • 11

1 Answers1

0

In general, the way forward in this kind of situation is to create a slide that looks the way you want using PowerPoint (by hand), then inspect the XML it creates to see how it approaches the feature.

Unfortunately, neither PowerPoint or OpenOffice are completely compliant with the spec and they exhibit unexpected behaviors, especially around the fringes, in the less-used features. So even though I expect you'll find that python-pptx is producing the expected XML in this situation, for some reason PowerPoint is not interpreting that as the spec would state.

But there's a very high likelihood that if you can get PowerPoint to rotate the image without disappearing it, that doing the same thing to the XML that it does will produce the result you're after. So that's where I'd start.

It is a little suspicious that it's a picture placeholder though, I'd first try it with a normal picture shape and see if it has the same problem. That's liable to narrow it down either way.

scanny
  • 26,423
  • 5
  • 54
  • 80
  • It looks easier to me to design the Powerpoint template using different kind of layouts. One of them with a picture placeholder so I do not need to insert any shape. Maybe the problem is that I cannot rotate PlaceholderPicture, but it is strange to me because the docs say I would. Is your solution then to create new slide and add the Picture as a shape and then try to rotate it ? – danieltellez Aug 08 '17 at 18:45
  • @danieltellez I think you have to make a choice, whether you want to diagnose the problem or just try different things to find something that works. Both are legitimate approaches. I don't know exactly what will make this work, so I'm advising on the approaches. If you get a working example in PowerPoint and compare the shape XML to that generated by python-pptx, that will very likely lead to a precise diagnosis. Then you would work out how to get the XML to look the way it needs to. – scanny Aug 08 '17 at 18:51
  • @danieltellez On the suggestion of trying it with a normal picture shape, I'm not suggesting you do the final implementation that way, just that you run that little experiment to see if it makes any difference in the behavior you see. I'm inclined to think it would be a useful data point as you explore further. – scanny Aug 08 '17 at 18:52
  • It finally work by rotating the image with PIL before the insertion into the placeholder. So I found something that works. Anyway, I'll try your approach in the next few days to know what way is better for the future. Thank you !! – danieltellez Aug 09 '17 at 14:24