1

I am doing process automation. it involve adding of images to the slides (total 8 images, 2 per slide, even some text below it.). I could add the image using pptx. but images need some cropping. How do I go about cropping it ? I also need to use some specific format for the slide. How to use that layout ? If someone can give process flow for doing it, would be grateful.

4
  • pillow.readthedocs.io/en/4.3.x, python-pptx.readthedocs.io/en/latest Commented Nov 8, 2017 at 7:35
  • I dont know why there is a downvote. but I have those docs provided. I didnt get idea there, so came here to ask. Commented Nov 8, 2017 at 9:09
  • What kind of cropping do your images need exactly? What is the layout you want to use? What have you tried so far? Commented Nov 8, 2017 at 10:05
  • My image has two parts on white backgrnd (cannot put the image here). I want them to be placed on particular slide side by side. its a common layout we use in our organisation. what i have tried so far >>> normal way of inserting picture using python-pptx. Commented Nov 8, 2017 at 13:16

2 Answers 2

2

A picture shape in python-pptx has four crop properties (.crop_left, .crop_top, etc.). These each take a float value with e.g. 0.1 corresponding to 10%.

but unfortunately these are read-only at present. If you need to crop your photos, you'll need to do it by hand or perhaps pre-process the images with something like the Python Imaging Library (PIL/Pillow) to modify their extents before inserting them.

An image can be added to a slide in two ways. Either you can add it as a separate shape at an arbitrary location using slide.shapes.add_picture(), or you can add an image placeholder to the layout you use to create the slide and use placeholder.insert_picture(). This latter approach automatically draws the position and size from the placeholder, which helps keep those consistent across slides using that layout.

Sign up to request clarification or add additional context in comments.

1 Comment

Picture-crop setters were added in release 0.6.9 of python-pptx on Wed May 9, 2018. So these are now read/write properties on Picture.
1

Maybe you could use SlideMight, a data merge tool for PowerPoint.

Suppose you have the images in files, and a data file listing the file locations or URLs. You would then make a "pattern file", which is much like a PowerPoint template. There you make a slide with a table having 2 rows or columns; each image will get into a cell. You may add extra rows for some texts. Alternatively you can predefine 4 slides each having 2 placeholders for images, which are then named like image1 to image8.

Then let SlideMight generate the desired presentation. SlideMight will do the resizing, and span the table over extra slides as needed. Normally SlideMight runs in a GUI. It should also be able to run as a command line program, although this has not been tested lately (please let me know if you need it).

Would this be of use?

Disclaimer: I am the developer and vendor of SlideMight.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.