scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.26k stars 499 forks source link

save picture as SVG #885

Open MiaLinlinLu opened 1 year ago

MiaLinlinLu commented 1 year ago

could you add some save_as option for Picture class or Image class? Thanks!

sedrew commented 1 year ago

The Image class does not support svg format. Immutable value object representing an image such as a JPEG, PNG, or GIF. But you can save it in a different format.


from pptx import Presentation
from PIL import Image as PIL_Image
from pptx.compat import BytesIO

shape = Presentation('file').slides[0].shapes[0]
stream = BytesIO(shape.image.blob)
pil_image = PIL_Image.open(stream)
pil_image.save('file_path', bitmap_format='png')