from pypng.code import png
from base64 import standard_b64encode, standard_b64decode
from StringIO import StringIO


def encode(string):
    """ PNG-compress the string, return the b64 encoded bytes """
    bytes = list(bytearray(string))
    png_image = png.from_array([bytes], 'L')
    buff = StringIO()
    png_image.save(buff)
    encoded = standard_b64encode(buff.getvalue())
    return encoded

def decode(string):
    """ b64 decode the string, then PNG-decompress """
    decoded = standard_b64decode(string)
    reader = png.Reader(bytes=decoded)
    width, height, rawpixels, metadata = reader.read()
    pixels = list(rawpixels)[0]
    return str(bytearray(pixels))

@@ -20,16 +20,38 @@
 ort png%0A
+from PIL import Image%0A
 from bas
@@ -226,83 +226,58 @@
     
-bytes = list(bytearray(string))%0A    png_image = png.from_array(%5Bbytes%5D, 'L'
+i = Image.fromstring('L', (len(string), 1), string
 )%0A  
@@ -304,17 +304,9 @@
     
-png_image
+i
 .sav
@@ -311,16 +311,23 @@
 ave(buff
+, %22png%22
 )%0A    en

Use python imaging library to encode PNG instead of pypng