Browse Source

Add handling for python 2 base64 encoding

master
Josh Gordon 4 years ago
parent
commit
58d8a798f5
  1. 9
      app/dungeon.py

9
app/dungeon.py

@ -280,6 +280,8 @@ def drawGrid(im,mask): #draws grid on canonicalized image
gridded = cv2.bitwise_and(newim,newim,mask=mask)
return gridded
#this function should really just be always in python 3
#maybe have it run this file in python 3 and capture output?
def genGridDungeonB64(gSizeX,gSizeY,mScale,imScale,numCells=None):
global MAP_SCALE
global WALL_SCALE
@ -303,8 +305,11 @@ def genGridDungeonB64(gSizeX,gSizeY,mScale,imScale,numCells=None):
#cv2.imshow("here",im)
#cv2.waitKey(0)
#base64 encode as jpg
ret,buf = cv2.imencode('.png',im)
enc = base64.b64encode(buf)
ret,buf = cv2.imencode('.jpg',im)
if sys.version_info.major >= 3:
enc = base64.b64encode(buf)
else:
enc = buf.tostring().encode("base64")
return enc
#s = genGridDungeonB64(10,10,8,24)

Loading…
Cancel
Save