Skip to content

Commit abc67ed

Browse files
committed
Merge branch 'develop' of https://github.com/japonicus/PHPWord into develop
2 parents a5b5e0c + 833dfea commit abc67ed

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/PhpWord/Element/Image.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,17 @@ public function __construct($source, $style = null, $isWatermark = false)
131131
$this->source = $source;
132132
$this->isWatermark = $isWatermark;
133133
$this->style = $this->setStyle(new ImageStyle(), $style, true);
134-
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
135-
$this->style->setWidth($imgData[0]);
136-
$this->style->setHeight($imgData[1]);
134+
$styleWidth = $this->style->getWidth();
135+
$styleHeight = $this->style->getHeight();
136+
if (!($styleWidth && $styleHeight)) {
137+
if ($styleWidth == null && $styleHeight == null) {
138+
$this->style->setWidth($imgData[0]);
139+
$this->style->setHeight($imgData[1]);
140+
} else if ($styleWidth) {
141+
$this->style->setHeight($imgData[1] * ($styleWidth / $imgData[0]));
142+
} else {
143+
$this->style->setWidth($imgData[0] * ($styleHeight / $imgData[1]));
144+
}
137145
}
138146
$this->setImageFunctions();
139147
}

0 commit comments

Comments
 (0)