PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/add-ons/PHPExcel/PHPExcel/Worksheet/MemoryDrawing.php

https://github.com/jcplat/console-seolan
PHP | 252 lines | 88 code | 29 blank | 135 comment | 4 complexity | 426c0fac18a8d639c8ee5d2929ee2333 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.1, 2009-11-02
  26. */
  27. /** PHPExcel root directory */
  28. if (!defined('PHPEXCEL_ROOT')) {
  29. /**
  30. * @ignore
  31. */
  32. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
  33. }
  34. /** PHPExcel_IComparable */
  35. require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
  36. /** PHPExcel_Worksheet */
  37. require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
  38. /** PHPExcel_Worksheet_BaseDrawing */
  39. require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/BaseDrawing.php';
  40. /** PHPExcel_Worksheet_Drawing_Shadow */
  41. require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/Drawing/Shadow.php';
  42. /**
  43. * PHPExcel_Worksheet_MemoryDrawing
  44. *
  45. * @category PHPExcel
  46. * @package PHPExcel_Worksheet
  47. * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  48. */
  49. class PHPExcel_Worksheet_MemoryDrawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  50. {
  51. /* Rendering functions */
  52. const RENDERING_DEFAULT = 'imagepng';
  53. const RENDERING_PNG = 'imagepng';
  54. const RENDERING_GIF = 'imagegif';
  55. const RENDERING_JPEG = 'imagejpeg';
  56. /* MIME types */
  57. const MIMETYPE_DEFAULT = 'image/png';
  58. const MIMETYPE_PNG = 'image/png';
  59. const MIMETYPE_GIF = 'image/gif';
  60. const MIMETYPE_JPEG = 'image/jpeg';
  61. /**
  62. * Image resource
  63. *
  64. * @var resource
  65. */
  66. private $_imageResource;
  67. /**
  68. * Rendering function
  69. *
  70. * @var string
  71. */
  72. private $_renderingFunction;
  73. /**
  74. * Mime type
  75. *
  76. * @var string
  77. */
  78. private $_mimeType;
  79. /**
  80. * Unique name
  81. *
  82. * @var string
  83. */
  84. private $_uniqueName;
  85. /**
  86. * Create a new PHPExcel_Worksheet_MemoryDrawing
  87. */
  88. public function __construct()
  89. {
  90. // Initialise values
  91. $this->_imageResource = null;
  92. $this->_renderingFunction = self::RENDERING_DEFAULT;
  93. $this->_mimeType = self::MIMETYPE_DEFAULT;
  94. $this->_uniqueName = md5(rand(0, 9999). time() . rand(0, 9999));
  95. // Initialize parent
  96. parent::__construct();
  97. }
  98. /**
  99. * Get image resource
  100. *
  101. * @return resource
  102. */
  103. public function getImageResource() {
  104. return $this->_imageResource;
  105. }
  106. /**
  107. * Set image resource
  108. *
  109. * @param $value resource
  110. * @return PHPExcel_Worksheet_MemoryDrawing
  111. */
  112. public function setImageResource($value = null) {
  113. $this->_imageResource = $value;
  114. if (!is_null($this->_imageResource)) {
  115. // Get width/height
  116. $this->_width = imagesx($this->_imageResource);
  117. $this->_height = imagesy($this->_imageResource);
  118. }
  119. return $this;
  120. }
  121. /**
  122. * Get rendering function
  123. *
  124. * @return string
  125. */
  126. public function getRenderingFunction() {
  127. return $this->_renderingFunction;
  128. }
  129. /**
  130. * Set rendering function
  131. *
  132. * @param string $value
  133. * @return PHPExcel_Worksheet_MemoryDrawing
  134. */
  135. public function setRenderingFunction($value = PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT) {
  136. $this->_renderingFunction = $value;
  137. return $this;
  138. }
  139. /**
  140. * Get mime type
  141. *
  142. * @return string
  143. */
  144. public function getMimeType() {
  145. return $this->_mimeType;
  146. }
  147. /**
  148. * Set mime type
  149. *
  150. * @param string $value
  151. * @return PHPExcel_Worksheet_MemoryDrawing
  152. */
  153. public function setMimeType($value = PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT) {
  154. $this->_mimeType = $value;
  155. return $this;
  156. }
  157. /**
  158. * Get indexed filename (using image index)
  159. *
  160. * @return string
  161. */
  162. public function getIndexedFilename() {
  163. $extension = strtolower($this->getMimeType());
  164. $extension = explode('/', $extension);
  165. $extension = $extension[1];
  166. return $this->_uniqueName . $this->getImageIndex() . '.' . $extension;
  167. }
  168. /**
  169. * Get hash code
  170. *
  171. * @return string Hash code
  172. */
  173. public function getHashCode() {
  174. return md5(
  175. $this->_renderingFunction
  176. . $this->_mimeType
  177. . $this->_uniqueName
  178. . parent::getHashCode()
  179. . __CLASS__
  180. );
  181. }
  182. /**
  183. * Hash index
  184. *
  185. * @var string
  186. */
  187. private $_hashIndex;
  188. /**
  189. * Get hash index
  190. *
  191. * Note that this index may vary during script execution! Only reliable moment is
  192. * while doing a write of a workbook and when changes are not allowed.
  193. *
  194. * @return string Hash index
  195. */
  196. public function getHashIndex() {
  197. return $this->_hashIndex;
  198. }
  199. /**
  200. * Set hash index
  201. *
  202. * Note that this index may vary during script execution! Only reliable moment is
  203. * while doing a write of a workbook and when changes are not allowed.
  204. *
  205. * @param string $value Hash index
  206. */
  207. public function setHashIndex($value) {
  208. $this->_hashIndex = $value;
  209. }
  210. /**
  211. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  212. */
  213. public function __clone() {
  214. $vars = get_object_vars($this);
  215. foreach ($vars as $key => $value) {
  216. if (is_object($value)) {
  217. $this->$key = clone $value;
  218. } else {
  219. $this->$key = $value;
  220. }
  221. }
  222. }
  223. }