Skip to content

Commit

Permalink
base64 works for Py3 again
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Guglielmetti committed Jan 5, 2016
1 parent 5777122 commit c074aa3
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Goulib/image.py
Expand Up @@ -12,13 +12,13 @@
__credits__ = ['Brad Montgomery http://bradmontgomery.net']
__license__ = "LGPL"

import six

from PIL import Image as PILImage
from PIL import ImagePalette, ImageOps

import numpy as np

import six, math, base64

from . import math2

class Image(PILImage.Image):
Expand Down Expand Up @@ -113,16 +113,14 @@ def base64(self, fmt='PNG'):
:result: string base64 encoded image content in specified format
"""
# http://stackoverflow.com/questions/31826335/how-to-convert-pil-image-image-object-to-base64-string

import base64
import cStringIO

buffer = cStringIO.StringIO()
buffer = six.BytesIO()
self.save(buffer, format=fmt)
return base64.b64encode(buffer.getvalue())

def to_html(self):
return r'<img src="data:image/png;base64,{0}">'.format(self.base64('PNG'))
s=self.base64('PNG').decode('utf-8')
return r'<img src="data:image/png;base64,{0}">'.format(s)

def html(self):
from IPython.display import HTML
Expand Down

0 comments on commit c074aa3

Please sign in to comment.