Я пытаюсь прочитать файл .pptx, используя python-pptx. Мне удалось получить весь контент, кроме изображения из презентации. Ниже приведен код, который я использовал для идентификации изображений, отличных от текстовых фреймов, в презентации. После идентификации я получаю auto_shape_type как RECTANGLE (1), но ничего об изображении.
from pptx import Presentation
from pptx.shapes.picture import Picture
def read_ppt(file):
prs = Presentation(file)
for slide_no, slide in enumerate(prs.slides):
for shape in slide.shapes:
if not shape.has_text_frame:
print(shape.auto_shape_type)
Любая помощь в понимании этой проблемы приветствуется. Альтернативные варианты также приветствуются.






попробуйте запросить shape.shape_type. по умолчанию auto_shape_type возвращает прямоугольник, как вы заметили, хотя изображения можно вставлять и маскировать другими фигурами.
Note the default value for a newly-inserted picture is
MSO_AUTO_SHAPE_TYPE.RECTANGLE, which performs no cropping because the extents of the rectangle exactly correspond to the extents of the picture.
Unique integer identifying the type of this shape, unconditionally
MSO_SHAPE_TYPE.PICTUREin this case.
Вы можете извлечь содержимое изображения в файл, используя его свойство blob и записав двоичный файл:
from pptx import Presentation
pres = Presentation('ppt_image.pptx')
slide = pres.slides[0]
shape = slide.shapes[0]
image = shape.image
blob = image.blob
ext = image.ext
with open(f'image.{ext}', 'wb') as file:
file.write(blob)
Спасибо за ваше время. Не могли бы вы помочь мне в извлечении изображения из ppt?