-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathImage.php
68 lines (54 loc) · 1.76 KB
/
Image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* @package php-svg-lib
* @link http://github.com/PhenX/php-svg-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license GNU LGPLv3+ http://www.gnu.org/copyleft/lesser.html
*/
namespace Svg\Tag;
use Svg\Style;
class Image extends AbstractTag
{
protected $x = 0;
protected $y = 0;
protected $width = 0;
protected $height = 0;
protected $href = null;
protected function before($attributes)
{
parent::before($attributes);
$surface = $this->document->getSurface();
$surface->save();
$this->applyTransform($attributes);
}
public function start($attributes)
{
$height = $this->document->getHeight();
$width = $this->document->getWidth();
$this->y = $height;
if (isset($attributes['x'])) {
$this->x = $this->convertSize($attributes['x'], $width);
}
if (isset($attributes['y'])) {
$this->y = $height - $this->convertSize($attributes['y'], $height);
}
if (isset($attributes['width'])) {
$this->width = $this->convertSize($attributes['width'], $width);
}
if (isset($attributes['height'])) {
$this->height = $this->convertSize($attributes['height'], $height);
}
if (isset($attributes['xlink:href'])) {
$this->href = $attributes['xlink:href'];
}
if (isset($attributes['href'])) {
$this->href = $attributes['href'];
}
$this->document->getSurface()->transform(1, 0, 0, -1, 0, $height);
$this->document->getSurface()->drawImage($this->href, $this->x, $this->y, $this->width, $this->height);
}
protected function after()
{
$this->document->getSurface()->restore();
}
}