I'm trying to parse a docx file, which contains an image, with PHPWord.
$image = $textRun_element -> getImageStringData(true);
$image_type = $textRun_element -> getImageType();
$image_style = $textRun_element -> getStyle();
$width = $image_style -> getWidth();
Using this code I get the original image width, but in the word document the image has smaller size and I need to get the image size as it is seen in the document (for example, the original image has width 12.28 cm and in the document its size is set at 6.11 cm).
Is there any way to get the image size, which is set in the Word document?
Edited.
After studying some of the PHPWord files it seems to me, that this is some kind of a bug. File \phpoffice\phpword\src\PhpWord\Element\Image.php contains a piece of code
/**
* Set proportional width/height if one dimension not available.
*
* @param int $actualWidth
* @param int $actualHeight
*/
private function setProportionalSize($actualWidth, $actualHeight)
{
$styleWidth = $this->style->getWidth();
$styleHeight = $this->style->getHeight();
if (!($styleWidth && $styleHeight)) {
if ($styleWidth == null && $styleHeight == null) {
$this->style->setWidth($actualWidth);
$this->style->setHeight($actualHeight);
} elseif ($styleWidth) {
$this->style->setHeight($actualHeight * ($styleWidth / $actualWidth));
} else {
$this->style->setWidth($actualWidth * ($styleHeight / $actualHeight));
}
}
}
If I get it right, this function checks, if an Image object has defined properties width and height in its style and if not, takes these values from the actual image in the docx archive, or if one of these properties is defined and the other is not, it calculates the other one, using the actual image size.
I put an echo into the if ($styleWidth == null && $styleHeight == null){} part to see if the condition is true, and this echo was triggered. So, this means, that Image object created during parsing has undefined style properties width and height.
Now I just don't get, which part of the PHPWord Word 2007 Reader code should get these properties from docx.
I'm sorry if I used some of the terminology incorrectly, I'm completely new to the object-oriented programming.