Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/PhpWord/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class Image extends AbstractElement
*/
private $watermark;

/**
* Name of image
*
* @var string
*/
private $name;

/**
* Image type
*
Expand Down Expand Up @@ -129,11 +136,12 @@ class Image extends AbstractElement
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function __construct($source, $style = null, $watermark = false)
public function __construct($source, $style = null, $watermark = false, $name = null)
{
$this->source = $source;
$this->setIsWatermark($watermark);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->name = $name;

$this->checkImage($source);
}
Expand Down Expand Up @@ -168,6 +176,16 @@ public function getSourceType()
return $this->sourceType;
}

/**
* Get image name
*
* @return null|string
*/
public function getName()
{
return $this->name;
}

/**
* Get image media ID
*
Expand Down
10 changes: 10 additions & 0 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent,
$imageSource = "zip://{$this->docFile}#{$target}";
$parent->addImage($imageSource);
}

// Other Images
} elseif ($xmlReader->elementExists('w:drawing', $domNode)) {
$name = $xmlReader->getAttribute('name', $domNode, 'w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
$embedId = $xmlReader->getAttribute('r:embed', $domNode, 'w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
$target = $this->getMediaTarget($docPart, $embedId);
if (!is_null($target)) {
$imageSource = "zip://{$this->docFile}#{$target}";
$parent->addImage($imageSource, null, false, $name);
}

// Object
} elseif ($xmlReader->elementExists('w:object', $domNode)) {
Expand Down
3 changes: 3 additions & 0 deletions src/PhpWord/Shared/XMLReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public function getElements($path, \DOMElement $contextNode = null)
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
// GT Mod - required for reading images
$this->xpath->registerNamespace('a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
$this->xpath->registerNamespace('pic', 'http://schemas.openxmlformats.org/drawingml/2006/picture');
}

if (is_null($contextNode)) {
Expand Down