0

How do you do this without saving to disk and then opening 'out.png' ?

    r = requests.get(url)
    mine,encoded =  r.json()[0]['data'].split(',') #if it is segmentation
    decoded = base64.decodestring(encoded)

    if mine == 'data:image/png;base64':
        #TODO do this from memory
        g = open("out.png", "w")
        g.write(decoded)
        g.close()            

        r = png.Reader('out.png')
        print r.read()

2 Answers2

0

Use the bytes keyword

r = png.Reader(bytes=decoded)
Daniel
  • 42,087
  • 4
  • 55
  • 81
0

base53.decodestring() returns a string of the binary data, and according to this page png.Reader() can take a string as input, so you just have to link the two together.

ErikR
  • 51,541
  • 9
  • 73
  • 124