1<?php
2
3namespace RtfHtmlPhp\Html;
4
5class Image
6{
7    /**
8     * Object constructor.
9     */
10    public function __construct()
11    {
12        $this->reset();
13    }
14
15    /**
16     * Resets the object to the initial state
17     *
18     * @return void
19     */
20    public function reset()
21    {
22        $this->format = 'bmp';
23        $this->width = 0;         // in xExt if wmetafile otherwise in px
24        $this->height = 0;        // in yExt if wmetafile otherwise in px
25        $this->goalWidth = 0;     // in twips
26        $this->goalHeight = 0;    // in twips
27        $this->pcScaleX = 100;    // 100%
28        $this->pcScaleY = 100;    // 100%
29        $this->binarySize = null; // Number of bytes of the binary data
30        $this->imageData = null;  // Binary or Hexadecimal Data
31    }
32
33    /**
34     * Generate a HTML content for the image
35     *
36     * @return string <img> tag content, An empty string for unsupported/empty image
37     */
38    public function printImage()
39    {
40        // process binary data
41        if (isset($this->binarySize)) {
42            // Not implemented
43            return '';
44        }
45
46        if (empty($this->imageData)) {
47            return '';
48        }
49
50        // process hexadecimal data
51        $data = base64_encode(pack('H*', $this->imageData));
52
53        // <img src="data:image/{FORMAT};base64,{#BDATA}" />
54        return "<img src=\"data:image/{$this->format};base64,{$data}\" />";
55    }
56}
57