File Source for MemoryDrawing.php

PHPExcel_Worksheet

# Source for file MemoryDrawing.php

Documentation is available at MemoryDrawing.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 PHPExcel
6. *
7. * This library is free software; you can redistribute it and/or
8. * modify it under the terms of the GNU Lesser General Public
9. * License as published by the Free Software Foundation; either
10. * version 2.1 of the License, or (at your option) any later version.
11. *
12. * This library is distributed in the hope that it will be useful,
13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15. * Lesser General Public License for more details.
16. *
17. * You should have received a copy of the GNU Lesser General Public
18. * License along with this library; if not, write to the Free Software
19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20. *
21. * @category PHPExcel
22. * @package PHPExcel_Worksheet
23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Worksheet_MemoryDrawing
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Worksheet
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Worksheet_MemoryDrawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
37. {
38. /* Rendering functions */
39. const RENDERING_DEFAULT = 'imagepng';
40. const RENDERING_PNG = 'imagepng';
41. const RENDERING_GIF = 'imagegif';
42. const RENDERING_JPEG = 'imagejpeg';
44. /* MIME types */
45. const MIMETYPE_DEFAULT = 'image/png';
46. const MIMETYPE_PNG = 'image/png';
47. const MIMETYPE_GIF = 'image/gif';
48. const MIMETYPE_JPEG = 'image/jpeg';
50. /**
51. * Image resource
52. *
53. * @var resource
54. */
55. private $_imageResource;
57. /**
58. * Rendering function
59. *
60. * @var string
61. */
62. private $_renderingFunction;
64. /**
65. * Mime type
66. *
67. * @var string
68. */
69. private $_mimeType;
71. /**
72. * Unique name
73. *
74. * @var string
75. */
76. private $_uniqueName;
78. /**
79. * Create a new PHPExcel_Worksheet_MemoryDrawing
80. */
81. public function __construct()
82. {
83. // Initialise values
84. $this->_imageResource = null;
85. $this->_renderingFunction = self:: RENDERING_DEFAULT;
86. $this->_mimeType = self:: MIMETYPE_DEFAULT;
87. $this->_uniqueName = md5( rand(0, 9999). time() . rand(0, 9999));
89. // Initialize parent
90. parent::__construct();
91. }
93. /**
94. * Get image resource
95. *
96. * @return resource
97. */
98. public function getImageResource() {
99. return $this->_imageResource;
100. }
102. /**
103. * Set image resource
104. *
105. * @param $value resource
106. * @return PHPExcel_Worksheet_MemoryDrawing
107. */
108. public function setImageResource($value = null) {
109. $this->_imageResource = $value;
111. if (! is_null($this->_imageResource)) {
112. // Get width/height
113. $this->_width = imagesx($this->_imageResource);
114. $this->_height = imagesy($this->_imageResource);
115. }
116. return $this;
117. }
119. /**
120. * Get rendering function
121. *
122. * @return string
123. */
124. public function getRenderingFunction() {
125. return $this->_renderingFunction;
126. }
128. /**
129. * Set rendering function
130. *
131. * @param string $value
132. * @return PHPExcel_Worksheet_MemoryDrawing
133. */
134. public function setRenderingFunction($value = PHPExcel_Worksheet_MemoryDrawing:: RENDERING_DEFAULT) {
135. $this->_renderingFunction = $value;
136. return $this;
137. }
139. /**
140. * Get mime type
141. *
142. * @return string
143. */
144. public function getMimeType() {
145. return $this->_mimeType;
146. }
148. /**
149. * Set mime type
150. *
151. * @param string $value
152. * @return PHPExcel_Worksheet_MemoryDrawing
153. */
154. public function setMimeType($value = PHPExcel_Worksheet_MemoryDrawing:: MIMETYPE_DEFAULT) {
155. $this->_mimeType = $value;
156. return $this;
157. }
159. /**
160. * Get indexed filename (using image index)
161. *
162. * @return string
163. */
164. public function getIndexedFilename() {
165. $extension = strtolower($this-> getMimeType());
166. $extension = explode('/', $extension);
167. $extension = $extension[1];
169. return $this->_uniqueName . $this-> getImageIndex() . '.' . $extension;
170. }
172. /**
173. * Get hash code
174. *
175. * @return string Hash code
176. */
177. public function getHashCode() {
178. return md5(
179. $this->_renderingFunction
180. . $this->_mimeType
181. . $this->_uniqueName
182. . parent:: getHashCode()
183. . __CLASS__
184. );
185. }
187. /**
188. * Implement PHP __clone to create a deep clone, not just a shallow copy.
189. */
190. public function __clone() {
191. $vars = get_object_vars($this);
192. foreach ($vars as $key => $value) {
193. if ( is_object($value)) {
194. $this->$key = clone $value;
195. } else {
196. $this->$key = $value;
197. }
198. }
199. }
200. }

Documentation generated on Sun, 27 Feb 2011 16:32:47 -0800 by phpDocumentor 1.4.3