1. 2. /**
3. * PHP Flash Slide Show
4. *
5. * Create simple flash slideshow from sequences of JPEG images
6. * Requirement:
7. * You MUST have PHP with Ming installed as PHP Extension
8. * see http://ming.sourceforge.net and http://php.net/manual/en/ref.ming.php
9. * Ask your web server administrator if you don't know how to install it
10. *
11. * @author Adi Setiawan
12. * @license GNU/GPL
13. * @version 0.2
14. */
15.
16.
17. class flashSlideShow
18. {
19. //initiate needed variables
20. var $movie;
21. var $i;
22. var $width;
23. var $height;
24. var $bgred;
25. var $bggreen;
26. var $bgblue;
27. var $interval;
28.
29. /**
30. * Constructor
31. *
32. * Create new object
33. *
34. * @access public
35. * @param integer $width movie width in pixel
36. * @param integer $height movie height in pixel
37. * @param integer $interval interval in second, between each image
38. * @param string $bgcolor movie background color in hex
39. * @return void
40. */
41. function flashSlideShow($width, $height, $interval = 1, $bgcolor = '#FFFFFF')
42. {
43. $this->width = $width;
44. $this->height = $height;
45.
46. $this->movie = new swfMovie();
47. $this->movie->setDimension($width, $height);
48. $this->movie->setRate(10);
49.
50. $this->setBgColor($bgcolor);
51. $this->setInterval($interval);
52. }
53.
54. /**
55. * Set slideshow interval
56. *
57. * Set slideshow interval between each image. interval in seconds
58. *
59. * @access public
60. * @param integer $interval interval in seconds
61. * @return void
62. */
63. function setInterval($interval)
64. {
65. if (
66. $this->interval = $interval*10;
67. } else {
68. $this->interval = 10;
69. }
70. }
71.
72. /**
73. * Set background color
74. *
75. * Set background color in hex
76. *
77. * @access public
78. * @param string $bgcolor movie background color in hex
79. * @return void
80. */
81. function setBgColor($bgcolor)
82. {
83. $this->bgred = hexdec(substr($bgcolor,0,2));
84. $this->bggreen = hexdec(substr($bgcolor,2,2));
85. $this->bgblue = hexdec(substr($bgcolor,4,2));
86. }
87.
88. /**
89. * Set background color in RGB Format
90. *
91. * Set background color in RGB Format
92. *
93. * @access public
94. * @param integer $red Red RGB Format Value for background color
95. * @param integer $green Green RGB Format Value for background color
96. * @param integer $blur Blue RGB Format Value for background color
97. * @return void
98. */
99. function setBgColorRGB($red,$green,$blue)
100. {
101. $this->bgred = $red;
102. $this->bggreen = $green;
103. $this->bgblue = $blue;
104. }
105.
106. /**
107. * Add image to slideshow
108. *
109. * Add one JPEG file to flash slideshow
110. *
111. * @access public
112. * @param string $filename JPEG filename
113. * @return void
114. */
115. function addImage($filename)
116. {
117. //$this->movie->add(new SWFBitmap(fopen($filename, "rb")));
118.
119. //create image object
120. $b = new SWFBitmap(fopen($filename,'rb'));
121. $s = new SWFShape();
122. $s->setRightFill($s->addFill($b));
123. $s->drawLine($this->width, 0);
124. $s->drawLine(0, $this->height);
125. $s->drawLine(-$this->width, 0);
126. $s->drawLine(0, -$this->height);
127.
128. //transition white to image
129. $this->i = $this->movie->add($s);
130. $r = 255;
131. for($n=0; $n<=5; ++$n) {
132. //$i->multColor(1.0-$n/10, 1.0, 1.0);
133. //$i->addColor(0xff*$n/20, 0, 0);
134. $this->i->addColor($r-30, $r-30, $r-30);
135. $this->movie->nextFrame();
136. $r = $r - 30;
137. }
138.
139. //static image
140. $this->i = $this->movie->add($s);
141. $this->addInterval();
142.
143. //transition image to white
144. $r = 0;
145. for($n=0; $n<=5; ++$n)
146. {
147. //$i->multColor(1.0-$n/10, 1.0, 1.0);
148. //$i->addColor(0xff*$n/20, 0, 0);
149. $this->i->addColor($r+30, $r+30, $r+30);
150. $this->movie->nextFrame();
151. $r = $r +30;
152. }
153. }
154.
155. /**
156. * Add array of image to slideshow
157. *
158. * Add array of JPEG files to flash slideshow
159. *
160. * @access public
161. * @param array $filename array of JPEG files
162. * @return void
163. */
164. function addImages($filearray)
165. {
166. foreach($filearray as $key => $val) {
167. $this->addImage($val);
168. }
169. }
170.
171. /**
172. * Add interval between each image
173. *
174. * Add interval between each image
175. *
176. * @access private
177. * @return void
178. */
179. function addInterval()
180. {
181. $i = 1;
182. while ($i <= $this->interval) {
183. $this->movie->nextFrame();
184. $i++;
185. }
186. }
187.
188. /**
189. * Save movie
190. *
191. * Save movie
192. *
193. * @access public
194. * @param string $filename name of movie file to saved
195. * @return void
196. */
197. function save($filename)
198. {
199. $this->movie->save($filename);
200. }
201.
202. /**
203. * Output movie
204. *
205. * output movie immediatelly
206. *
207. * @access public
208. * @return void
209. */
210. function output()
211. {
212. header("Content-Type:application/x-shockwave-flash");
213. $this->movie->output();
214. }
215. }
216. ?>
File tersebut disimpan dengan nama class.flashslideshow.php. Untuk menggunakannya, kita buat file dengan nama terserahanda.php dan disimpan dalam folder yang sama dengan file classnya.
1.
2. //include class file
3. include('class.flashslideshow.php');
4.
5. /*
6. create new object with the following variabel
7. flashSlideShow($width, $height, $interval, $bgcolor)
8. $width, movie width in pixel
9. $height, movie height in pixel
10. $interval, interval in seconds between each images
11. $bgcolor, movie backgground color in hexadecimal value1
2. */
13. $movie = new flashSlideShow(300, 225, 3, '#FFFFFF');
14.
15.
16. /* we add sequences of images in array
17. this array may come from readdir function,database query etc
18. */
19. $myfile = array('image1.jpg','image2.jpg','image3.jpg','image4.jpg','image5.jpg');
20. $movie->addImages($myfile);
21.
22. /*
23. output the flash
24. */
25. $movie->output();
26. ?>
No comments:
Post a Comment