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