Skip to content

Commit 34bda10

Browse files
gthomas2troosan
authored andcommitted
Fix images added in word 2011
1 parent 400ee57 commit 34bda10

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/PhpWord/Element/Image.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class Image extends AbstractElement
6565
*/
6666
private $watermark;
6767

68+
/**
69+
* Name of image
70+
*
71+
* @var string
72+
*/
73+
private $name;
74+
6875
/**
6976
* Image type
7077
*
@@ -131,11 +138,12 @@ class Image extends AbstractElement
131138
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
132139
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
133140
*/
134-
public function __construct($source, $style = null, $watermark = false)
141+
public function __construct($source, $style = null, $watermark = false, $name = null)
135142
{
136143
$this->source = $source;
137144
$this->setIsWatermark($watermark);
138145
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
146+
$this->name = $name;
139147

140148
$this->checkImage();
141149
}
@@ -170,6 +178,16 @@ public function getSourceType()
170178
return $this->sourceType;
171179
}
172180

181+
/**
182+
* Get image name
183+
*
184+
* @return null|string
185+
*/
186+
public function getName()
187+
{
188+
return $this->name;
189+
}
190+
173191
/**
174192
* Get image media ID
175193
*

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ protected function readRunChild(XMLReader $xmlReader, \DOMElement $node, Abstrac
260260
}
261261
$parent->addImage($imageSource);
262262
}
263+
} elseif ($node->nodeName == 'w:drawing') {
264+
// Office 2011 Images
265+
$name = $xmlReader->getAttribute('name', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
266+
$embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
267+
$target = $this->getMediaTarget($docPart, $embedId);
268+
if (!is_null($target)) {
269+
$imageSource = "zip://{$this->docFile}#{$target}";
270+
$parent->addImage($imageSource, null, false, $name);
271+
}
263272
} elseif ($node->nodeName == 'w:object') {
264273
// Object
265274
$rId = $xmlReader->getAttribute('r:id', $node, 'o:OLEObject');

0 commit comments

Comments
 (0)