Reputation: 180
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.
Upvotes: 1
Views: 4974
Reputation: 29021
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.
Upvotes: 2
Reputation: 318
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.
Upvotes: 1