##// END OF EJS Templates
add unconfined, raw metadata to display.Image...
Min RK -
Show More
@@ -637,7 +637,9 b' class Image(DisplayObject):'
637 637 _FMT_PNG = u'png'
638 638 _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG]
639 639
640 def __init__(self, data=None, url=None, filename=None, format=u'png', embed=None, width=None, height=None, retina=False):
640 def __init__(self, data=None, url=None, filename=None, format=u'png',
641 embed=None, width=None, height=None, retina=False,
642 unconfined=False, metadata=None):
641 643 """Create a PNG/JPEG image object given raw data.
642 644
643 645 When this object is returned by an input cell or passed to the
@@ -678,6 +680,10 b' class Image(DisplayObject):'
678 680 from image data.
679 681 For non-embedded images, you can just set the desired display width
680 682 and height directly.
683 unconfined: bool
684 Set unconfined=True to disable max-width confinement of the image.
685 metadata: dict
686 Specify extra metadata to attach to the image.
681 687
682 688 Examples
683 689 --------
@@ -728,6 +734,8 b' class Image(DisplayObject):'
728 734 self.width = width
729 735 self.height = height
730 736 self.retina = retina
737 self.unconfined = unconfined
738 self.metadata = metadata
731 739 super(Image, self).__init__(data=data, url=url, filename=filename)
732 740
733 741 if retina:
@@ -756,12 +764,19 b' class Image(DisplayObject):'
756 764
757 765 def _repr_html_(self):
758 766 if not self.embed:
759 width = height = ''
767 width = height = klass = ''
760 768 if self.width:
761 769 width = ' width="%d"' % self.width
762 770 if self.height:
763 771 height = ' height="%d"' % self.height
764 return u'<img src="%s"%s%s/>' % (self.url, width, height)
772 if self.unconfined:
773 klass = ' class="unconfined"'
774 return u'<img src="{url}"{width}{height}{klass}/>'.format(
775 url=self.url,
776 width=width,
777 height=height,
778 klass=klass,
779 )
765 780
766 781 def _data_and_metadata(self):
767 782 """shortcut for returning metadata with shape information, if defined"""
@@ -770,6 +785,10 b' class Image(DisplayObject):'
770 785 md['width'] = self.width
771 786 if self.height:
772 787 md['height'] = self.height
788 if self.unconfined:
789 md['unconfined'] = self.unconfined
790 if self.metadata:
791 md.update(self.metadata)
773 792 if md:
774 793 return self.data, md
775 794 else:
@@ -22,6 +22,8 b' def test_image_size():'
22 22 nt.assert_equal(u'<img src="%s" width="200"/>' % (thisurl), img._repr_html_())
23 23 img = display.Image(url=thisurl)
24 24 nt.assert_equal(u'<img src="%s"/>' % (thisurl), img._repr_html_())
25 img = display.Image(url=thisurl, unconfined=True)
26 nt.assert_equal(u'<img src="%s" class="unconfined"/>' % (thisurl), img._repr_html_())
25 27
26 28 def test_retina_png():
27 29 here = os.path.dirname(__file__)
General Comments 0
You need to be logged in to leave comments. Login now