Gowtham
Gowtham

Reputation: 141

Unable to insert picture in slide

I am trying to read pictures from the file and inserting them into the slide. So far its working fine. But today its giving me an error : "'Image' object has no attribute '_ext'". I can see that image is same as other images and it is a .jpg image. I dont know why it is giving me this error. ValueError: unsupported image format, expected one of: dict_keys(['BMP', 'GIF', 'JPEG', 'PNG', 'TIFF', 'WMF']), got 'MPO'. I am using :

for file in os.listdir("C:/Users/me/Desktop/imageSourceFile") :
 print(file)
 pic = Slide.shapes.add_picture("C:/Users/me/Desktop/imageSourceFile" 
 + '/' + file, left=Inches(3), top=Inches(3), width= Inches(3),  
 height=Inches(3))

prs.save('C:/Users/me/Desktop/mypresentation.pptx')

Except this picture everything else is getting pulled into the slides. I am not able to understand what to do with this error. Thank you in advance.

Upvotes: 3

Views: 1954

Answers (2)

Gowtham
Gowtham

Reputation: 141

My problem is I am facing this error for many pictures in my presentation.

I still didn't found why this error is popping up, but I recently came up with a workaround for this.

from PIL import Image
import os


path = 'C:/Users/name/Sourcelocation/'
imagenames = os.listdir(path)

for imagename in imagenames:
    print(imagename)
try:
    im = Image.open(path + imagename)
    im.save(path + imagename)
except:
    pass

This way we can bypass the procedure of converting them online. Just before inserting picture running this code on those pictures will make sure this error won't happen to any of the pictures.

Upvotes: 2

Raj Stha
Raj Stha

Reputation: 1091

I was having a similar error and I found out that the .jpg image that was throwing this error was actually in stereo JPEG format. After converting the images to regular JPEG format I was able to insert them into PowerPoint slides using "pptx" library in python. I used following website to convert the files: https://image.online-convert.com/convert-to-jpg

Upvotes: 2

Related Questions