Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Image
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
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\HTML\Element;
19
20use PhpOffice\PhpWord\Element\Image as ImageElement;
21use PhpOffice\PhpWord\Writer\HTML\Style\Image as ImageStyleWriter;
22
23/**
24 * Image element HTML writer.
25 *
26 * @since 0.10.0
27 */
28class Image extends Text
29{
30    /**
31     * Write image.
32     *
33     * @return string
34     */
35    public function write()
36    {
37        if (!$this->element instanceof ImageElement) {
38            return '';
39        }
40        $content = '';
41        $imageData = $this->element->getImageStringData(true);
42        if ($imageData !== null) {
43            $styleWriter = new ImageStyleWriter($this->element->getStyle());
44            $style = $styleWriter->write();
45            $imageData = 'data:' . $this->element->getImageType() . ';base64,' . $imageData;
46
47            $content .= $this->writeOpening();
48            $content .= "<img border=\"0\" style=\"{$style}\" src=\"{$imageData}\"/>";
49            $content .= $this->writeClosing();
50        }
51
52        return $content;
53    }
54}