Python ValueError: embedded null byte when reading png file from bash pipe

前端 未结 1 931
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 16:40
from PIL import Image
from subprocess import Popen, PIPE

scr = Image.open(Popen.communicate(Popen([\'import\',\'-w\',\'0x02a00001\',\'png:-\'], stdout=PIPE))[0])
         


        
1条回答
  •  有刺的猬
    2021-01-01 17:12

    Try first to load raw data into a BytesIO container:

    from io import BytesIO
    from PIL import Image
    from subprocess import Popen, PIPE
    
    data = Popen.communicate(Popen(['import','-w','0x02a00001','png:-'], stdout=PIPE))[0]
    scr = Image.open(BytesIO(data))
    

    0 讨论(0)
提交回复
热议问题