forked from trojal/php-ro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionMovement.php
85 lines (67 loc) · 1.86 KB
/
ActionMovement.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Trojal\PhpRo;
class ActionMovement
{
public function __construct($header)
{
$this->header = & $header;
$this->frames = array();
}
public function getFrameCount()
{
return $this
->header['frameCount'];
}
public function addFrame(ActionFrame $actionFrame)
{
$this->frames[] = & $actionFrame;
}
public function getFrame($frameNumber)
{
return $this->frames[$frameNumber];
}
public function setDuration($duration)
{
$this->duration = & $duration;
}
public function getImage($imageType = PHPRO_IMG_GIF)
{
$this->getDimensions();
$renderedFrames = array();
$time = array();
foreach ($this->frames as &$frame) {
$renderedFrames[] = $frame->getImage($imageType);
$time[] = $this->duration * 2.5;
}
$gif = new \GIFEncoder (
$renderedFrames,
$time,
0,
2,
0xFF, 0, 0xFF,
0,
"bin"
);
return $gif->GetAnimation();
}
public function getDimensions()
{
if (isset($this->dimensions))
return $this->dimensions;
$this->dimensions = array(
'width' => 0,
'height' => 0
);
foreach ($this->frames as &$frame) {
$frameDimensions = $frame->getDimensions();
if ($this->dimensions['width'] < $frameDimensions['width'])
$this->dimensions['width'] = $frameDimensions['width'];
if ($this->dimensions['height'] < $frameDimensions['height'])
$this->dimensions['height'] = $frameDimensions['height'];
}
foreach ($this->frames as &$frame) {
$frame->dimensions = $this->dimensions;
}
return $this->dimensions;
}
}