簡體   English   中英

Python-pptx slide.shapes.add_picture()無法識別圖像文件

[英]Python-pptx slide.shapes.add_picture() not recognizing image files

我正在嘗試使用pptx將圖像添加到PowerPoint幻燈片。

img_path = 'test.png'

prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)

left = top = Inches(1)
pic = slide.shapes.add_picture(img_path, left, top)

每次運行此命令時(我嘗試了幾種不同的圖像,有些是由matplotlib生成的,有些是下載的),我從.add_picture()收到以下錯誤:

Continuum\Anaconda\lib\site-packages\pptx\parts\image.pyc in _size(self)
    158         image_stream = StringIO(self._blob)
--> 159         width_px, height_px = PIL_Image.open(image_stream).size
    160         image_stream.close()
    161         return width_px, height_px

Continuum\Anaconda\lib\site-packages\PIL\Image.pyc in open(fp, mode)
   1978     :param size: A 2-tuple, containing (width, height) in pixels.
   1979     :param color: What color to use for the image.  Default is black.
-> 1980        If given, this should be a single integer or floating point value
   1981        for single-band modes, and a tuple for multi-band modes (one value
   1982        per band).  When creating RGB images, you can also use color

IOError: cannot identify image file

我該怎么做才能解決此問題?

這看起來像是與PIL /枕頭庫有關的問題。 您能否進一步說明您所處的環境以及所使用的PIL版本? 我知道同時安裝PIL和Pillow時會出現一些潛在的問題。 如果您可以控制自己的Python環境,那么首先要卸載兩者,然后僅安裝最新版本的Pillow。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM