Browse Source

Fix base64 python2 issue

master
Josh Gordon 4 years ago
parent
commit
217a9084e4
  1. 13
      app/dungeon.py

13
app/dungeon.py

@ -5,6 +5,7 @@ import cv2
import base64
import sys
import subprocess
#algorithm: http://blankhead.fi/blog/index.php/2019/06/01/cell-flow-dungeon-layout-generation/
@ -283,6 +284,13 @@ def drawGrid(im,mask): #draws grid on canonicalized image
#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):
if sys.version_info.major < 3: #this here block of code is a sizeable ow
cmd = "from dungeon import genGridDungeonB64 as b; print(b({},{},{},{},{}))".format(gSizeX,gSizeY,mScale,imScale,numCells)
res = subprocess.check_output(["python3","-c",cmd])
return "bb"+res.split("\'")[-2]+"b" #padding required
global MAP_SCALE
global WALL_SCALE
MAP_SCALE = mScale
@ -306,10 +314,7 @@ def genGridDungeonB64(gSizeX,gSizeY,mScale,imScale,numCells=None):
#cv2.waitKey(0)
#base64 encode as jpg
ret,buf = cv2.imencode('.jpg',im)
if sys.version_info.major >= 3:
enc = base64.b64encode(buf)
else:
enc = buf.tostring().encode("base64")
enc = base64.b64encode(buf)
return enc
#s = genGridDungeonB64(10,10,8,24)

Loading…
Cancel
Save