Beispiel #1
0
    def add_picture(self, img_file, left, top, width=None, height=None):
        """
        Add picture shape displaying image in *img_file*, where *img_file*
        can be either a path to a file (a string) or a file-like object.
        """
        image, rId = self._slide._add_image(img_file)

        id = self._next_shape_id
        name = 'Picture %d' % (id-1)
        desc = image._desc
        width, height = image._scale(width, height)

        pic = CT_Picture.new_pic(id, name, desc, rId, left, top, width, height)

        self._spTree.append(pic)
        picture = Picture(pic, self)
        self._shapes.append(picture)
        return picture
Beispiel #2
0
 def test_new_pic_generates_correct_xml(self):
     """CT_Picture.new_pic() returns correct XML"""
     # setup ------------------------
     id_, name, desc, rId = 9, 'Picture 8', 'test-image.png', 'rId7'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:pic %s>\n  <p:nvPicPr>\n    <p:cNvPr id="%d" name="%s" descr='
         '"%s"/>\n    <p:cNvPicPr>\n      <a:picLocks noChangeAspect="1"/>'
         '\n    </p:cNvPicPr>\n    <p:nvPr/>\n  </p:nvPicPr>\n  <p:blipFil'
         'l>\n    <a:blip r:embed="%s"/>\n    <a:stretch>\n      <a:fillRe'
         'ct/>\n    </a:stretch>\n  </p:blipFill>\n  <p:spPr>\n    <a:xfrm'
         '>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/>'
         '\n    </a:xfrm>\n    <a:prstGeom prst="rect">\n      <a:avLst/>'
         '\n    </a:prstGeom>\n  </p:spPr>\n</p:pic>\n' %
         (nsdecls('a', 'p', 'r'), id_, name, desc, rId, left, top, width,
          height)
     )
     # exercise ---------------------
     pic = CT_Picture.new_pic(id_, name, desc, rId, left, top,
                              width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, pic)