Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Image
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * This file is part of PHPWord - A pure PHP library for reading and writing
4 * word processing documents.
5 *
6 * PHPWord is free software distributed under the terms of the GNU Lesser
7 * General Public License version 3 as published by the Free Software Foundation.
8 *
9 * For the full copyright and license information, please read the LICENSE
10 * file that was distributed with this source code. For the full list of
11 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12 *
13 * @see         https://github.com/PHPOffice/PHPWord
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18namespace PhpOffice\PhpWord\Writer\RTF\Element;
19
20use PhpOffice\PhpWord\Element\Image as ImageElement;
21use PhpOffice\PhpWord\Shared\Converter;
22
23/**
24 * Image element RTF writer.
25 *
26 * @since 0.11.0
27 */
28class Image extends AbstractElement
29{
30    /**
31     * Write element.
32     *
33     * @return string
34     */
35    public function write()
36    {
37        if (!$this->element instanceof ImageElement) {
38            return '';
39        }
40
41        $this->getStyles();
42        $style = $this->element->getStyle();
43
44        $content = '';
45        $content .= $this->writeOpening();
46        $content .= '{\*\shppict {\pict';
47        $content .= '\pngblip\picscalex100\picscaley100';
48        $content .= '\picwgoal' . round(Converter::pixelToTwip($style->getWidth()));
49        $content .= '\pichgoal' . round(Converter::pixelToTwip($style->getHeight()));
50        $content .= PHP_EOL;
51        $content .= $this->element->getImageStringData();
52        $content .= '}}';
53        $content .= $this->writeClosing();
54
55        return $content;
56    }
57}