| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 100.00% | 29 / 29 |  | 100.00% | 1 / 1 | CRAP |  | 100.00% | 1 / 1 | 
| Image |  | 100.00% | 29 / 29 |  | 100.00% | 1 / 1 | 4 |  | 100.00% | 1 / 1 | 
| write |  | 100.00% | 29 / 29 |  | 100.00% | 1 / 1 | 4 | |||
| 1 | <?php | 
| 2 | |
| 3 | /** | 
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing | 
| 5 | * word processing documents. | 
| 6 | * | 
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser | 
| 8 | * General Public License version 3 as published by the Free Software Foundation. | 
| 9 | * | 
| 10 | * For the full copyright and license information, please read the LICENSE | 
| 11 | * file that was distributed with this source code. For the full list of | 
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. | 
| 13 | * | 
| 14 | * @see https://github.com/PHPOffice/PHPWord | 
| 15 | * | 
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 | 
| 17 | */ | 
| 18 | |
| 19 | namespace PhpOffice\PhpWord\Writer\ODText\Element; | 
| 20 | |
| 21 | use PhpOffice\PhpWord\Element\Image as ElementImage; | 
| 22 | use PhpOffice\PhpWord\Shared\Converter; | 
| 23 | |
| 24 | /** | 
| 25 | * Image element writer. | 
| 26 | * | 
| 27 | * @since 0.10.0 | 
| 28 | */ | 
| 29 | class Image extends AbstractElement | 
| 30 | { | 
| 31 | /** | 
| 32 | * Write element. | 
| 33 | */ | 
| 34 | public function write(): void | 
| 35 | { | 
| 36 | $element = $this->getElement(); | 
| 37 | if (!$element instanceof ElementImage) { | 
| 38 | return; | 
| 39 | } | 
| 40 | |
| 41 | $mediaIndex = $element->getMediaIndex(); | 
| 42 | $target = 'Pictures/' . $element->getTarget(); | 
| 43 | $style = $element->getStyle(); | 
| 44 | $width = Converter::pixelToCm($style->getWidth()); | 
| 45 | $height = Converter::pixelToCm($style->getHeight()); | 
| 46 | |
| 47 | $xmlWriter = $this->getXmlWriter(); | 
| 48 | |
| 49 | if (!$this->withoutP) { | 
| 50 | $xmlWriter->startElement('text:p'); | 
| 51 | $xmlWriter->writeAttribute('text:style-name', 'IM' . $mediaIndex); | 
| 52 | } | 
| 53 | |
| 54 | $xmlWriter->startElement('draw:frame'); | 
| 55 | $xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex); | 
| 56 | $xmlWriter->writeAttributeIf($this->withoutP, 'draw:text-style-name', 'IM' . $mediaIndex); | 
| 57 | $xmlWriter->writeAttribute('draw:name', $element->getElementId()); | 
| 58 | $xmlWriter->writeAttribute('text:anchor-type', 'as-char'); | 
| 59 | $xmlWriter->writeAttribute('svg:width', $width . 'cm'); | 
| 60 | $xmlWriter->writeAttribute('svg:height', $height . 'cm'); | 
| 61 | $xmlWriter->writeAttribute('draw:z-index', $mediaIndex); | 
| 62 | |
| 63 | $xmlWriter->startElement('draw:image'); | 
| 64 | $xmlWriter->writeAttribute('xlink:href', $target); | 
| 65 | $xmlWriter->writeAttribute('xlink:type', 'simple'); | 
| 66 | $xmlWriter->writeAttribute('xlink:show', 'embed'); | 
| 67 | $xmlWriter->writeAttribute('xlink:actuate', 'onLoad'); | 
| 68 | $xmlWriter->endElement(); // draw:image | 
| 69 | |
| 70 | $xmlWriter->endElement(); // draw:frame | 
| 71 | |
| 72 | if (!$this->withoutP) { | 
| 73 | $xmlWriter->endElement(); // text:p | 
| 74 | } | 
| 75 | } | 
| 76 | } |