Fix images added in word 2011

This commit is contained in:
gthomas2 2015-01-06 17:20:27 +00:00 committed by troosan
parent 400ee57bee
commit 34bda10536
2 changed files with 28 additions and 1 deletions

View File

@ -65,6 +65,13 @@ class Image extends AbstractElement
*/
private $watermark;
/**
* Name of image
*
* @var string
*/
private $name;
/**
* Image type
*
@ -131,11 +138,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();
}
@ -170,6 +178,16 @@ class Image extends AbstractElement
return $this->sourceType;
}
/**
* Get image name
*
* @return null|string
*/
public function getName()
{
return $this->name;
}
/**
* Get image media ID
*

View File

@ -260,6 +260,15 @@ abstract class AbstractPart
}
$parent->addImage($imageSource);
}
} elseif ($node->nodeName == 'w:drawing') {
// Office 2011 Images
$name = $xmlReader->getAttribute('name', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
$embedId = $xmlReader->getAttribute('r:embed', $node, '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);
}
} elseif ($node->nodeName == 'w:object') {
// Object
$rId = $xmlReader->getAttribute('r:id', $node, 'o:OLEObject');