Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix height/width handling for Image object.

  • Loading branch information...
commit 820c8e62c0b1c5ec0e3398191ac4e16dcdf7f862 1 parent fb4a45e
@stefanv authored
Showing with 16 additions and 15 deletions.
  1. +16 −15 IPython/core/display.py
View
31 IPython/core/display.py
@@ -502,21 +502,22 @@ def reload(self):
super(Image,self).reload()
def _repr_html_(self):
- if not self.embed:
- width = height = ''
- if self.width:
- width = ' width="%d"' % self.width
- if self.height:
- height = ' height="%d"' % self.height
- return u'<img src="%s"%s%s/>' % (self.url, width, height)
-
- def _repr_png_(self):
- if self.embed and self.format == u'png':
- return self.data
-
- def _repr_jpeg_(self):
- if self.embed and (self.format == u'jpeg' or self.format == u'jpg'):
- return self.data
+ width = height = ''
+
+ if self.width:
+ width = ' width="%s" ' % self.width
+ if self.height:
+ height = ' height="%s" ' % self.height
+
+ if self.embed:
+ import base64
+ src = "data:image/%s;base64,%s" % (self.format,
+ base64.encodestring(self.data))
+ else:
+ src = self.url
+
+ return u'<img src="%s" %s %s>' % (src, width, height)
+
def _find_ext(self, s):
return unicode(s.split('.')[-1].lower())
Please sign in to comment.
Something went wrong with that request. Please try again.