Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Image | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| write | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpWord\Writer\EPub3\Element; |
| 4 | |
| 5 | use PhpOffice\PhpWord\Element\Image as ImageElement; |
| 6 | |
| 7 | /** |
| 8 | * Image element writer for EPub3. |
| 9 | */ |
| 10 | class Image extends AbstractElement |
| 11 | { |
| 12 | /** |
| 13 | * Write element. |
| 14 | */ |
| 15 | public function write(): void |
| 16 | { |
| 17 | $xmlWriter = $this->getXmlWriter(); |
| 18 | $xmlWriter->setIndent(false); |
| 19 | $element = $this->getElement(); |
| 20 | if (!$element instanceof ImageElement) { |
| 21 | return; |
| 22 | } |
| 23 | $mediaIndex = $element->getMediaIndex(); |
| 24 | $target = 'media/image' . $mediaIndex . '.' . $element->getImageExtension(); |
| 25 | if (!$this->withoutP) { |
| 26 | $xmlWriter->startElement('p'); |
| 27 | } |
| 28 | $xmlWriter->startElement('img'); |
| 29 | $xmlWriter->writeAttribute('src', $target); |
| 30 | $style = ''; |
| 31 | if ($element->getStyle()->getWidth() !== null) { |
| 32 | $style .= 'width:' . $element->getStyle()->getWidth() . 'px;'; |
| 33 | } |
| 34 | if ($element->getStyle()->getHeight() !== null) { |
| 35 | $style .= 'height:' . $element->getStyle()->getHeight() . 'px;'; |
| 36 | } |
| 37 | if ($style !== '') { |
| 38 | $xmlWriter->writeAttribute('style', $style); |
| 39 | } |
| 40 | $xmlWriter->endElement(); // img |
| 41 | if (!$this->withoutP) { |
| 42 | $xmlWriter->endElement(); // p |
| 43 | } |
| 44 | } |
| 45 | } |