python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

save picture as SVG

Open MiaLinlinLu opened this issue 1 year ago • 1 comments

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

MiaLinlinLu avatar May 04 '23 00:05 MiaLinlinLu

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')

sedrew avatar Jun 07 '23 07:06 sedrew