True when `drawing` contains an embedded picture. A drawing can contain a picture, but it can also contain a chart, SmartArt, or a drawing canvas. Methods related to a picture, like `.image`, will raise when the drawing does not contain a picture. Use this value to determine
(self)
| 22 | |
| 23 | @property |
| 24 | def has_picture(self) -> bool: |
| 25 | """True when `drawing` contains an embedded picture. |
| 26 | |
| 27 | A drawing can contain a picture, but it can also contain a chart, SmartArt, or a |
| 28 | drawing canvas. Methods related to a picture, like `.image`, will raise when the drawing |
| 29 | does not contain a picture. Use this value to determine whether image methods will succeed. |
| 30 | |
| 31 | This value is `False` when a linked picture is present. This should be relatively rare and |
| 32 | the image would only be retrievable from the filesystem. |
| 33 | |
| 34 | Note this does not distinguish between inline and floating images. The presence of either |
| 35 | one will cause this value to be `True`. |
| 36 | """ |
| 37 | xpath_expr = ( |
| 38 | # -- an inline picture -- |
| 39 | "./wp:inline/a:graphic/a:graphicData/pic:pic" |
| 40 | # -- a floating picture -- |
| 41 | " | ./wp:anchor/a:graphic/a:graphicData/pic:pic" |
| 42 | ) |
| 43 | # -- xpath() will return a list, empty if there are no matches -- |
| 44 | return bool(self._drawing.xpath(xpath_expr)) |
| 45 | |
| 46 | @property |
| 47 | def image(self) -> Image: |