code: def to_json(value, **kwargs):
          
          b64rep = base64.b64encode(value.read())
          value.seek(0)
          jsonrep = '{preamble}{b64}'.format(
              preamble=PNG_PREAMBLE,
              b64=b64rep.decode(),
          )
          return jsonrep
docs: Convert a PNG Image to base64-encoded JSON
  
          to_json assumes that value has passed validation.