34 from base64
import standard_b64encode, standard_b64decode
36 from math
import floor, ceil, sqrt
40 """ PNG-compress the string in a square RBG image padded with '\n', return the b64 encoded bytes """ 42 width = floor(sqrt(length/3.0))
43 height = ceil((length/3.0) / width)
44 bytes_needed = int(width * height * 3)
45 while length < bytes_needed:
48 i = Image.frombytes(
'RGB', (int(width), int(height)), string)
51 encoded = standard_b64encode(buff.getvalue())
55 """ b64 decode the string, then PNG-decompress """ 56 decoded = standard_b64decode(string)
57 buff = StringIO(decoded)