5 * Copyright (c) 2006 - 2014 PHPExcel
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.
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.
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
22 * @package PHPExcel_Worksheet
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
30 * PHPExcel_Worksheet_MemoryDrawing
33 * @package PHPExcel_Worksheet
34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
36 class PHPExcel_Worksheet_MemoryDrawing
extends PHPExcel_Worksheet_BaseDrawing
implements PHPExcel_IComparable
38 /* Rendering functions */
39 const RENDERING_DEFAULT
= 'imagepng';
40 const RENDERING_PNG
= 'imagepng';
41 const RENDERING_GIF
= 'imagegif';
42 const RENDERING_JPEG
= 'imagejpeg';
45 const MIMETYPE_DEFAULT
= 'image/png';
46 const MIMETYPE_PNG
= 'image/png';
47 const MIMETYPE_GIF
= 'image/gif';
48 const MIMETYPE_JPEG
= 'image/jpeg';
55 private $_imageResource;
62 private $_renderingFunction;
79 * Create a new PHPExcel_Worksheet_MemoryDrawing
81 public function __construct()
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));
90 parent
::__construct();
98 public function getImageResource() {
99 return $this->_imageResource
;
105 * @param $value resource
106 * @return PHPExcel_Worksheet_MemoryDrawing
108 public function setImageResource($value = null) {
109 $this->_imageResource
= $value;
111 if (!is_null($this->_imageResource
)) {
113 $this->_width
= imagesx($this->_imageResource
);
114 $this->_height
= imagesy($this->_imageResource
);
120 * Get rendering function
124 public function getRenderingFunction() {
125 return $this->_renderingFunction
;
129 * Set rendering function
131 * @param string $value
132 * @return PHPExcel_Worksheet_MemoryDrawing
134 public function setRenderingFunction($value = PHPExcel_Worksheet_MemoryDrawing
::RENDERING_DEFAULT
) {
135 $this->_renderingFunction
= $value;
144 public function getMimeType() {
145 return $this->_mimeType
;
151 * @param string $value
152 * @return PHPExcel_Worksheet_MemoryDrawing
154 public function setMimeType($value = PHPExcel_Worksheet_MemoryDrawing
::MIMETYPE_DEFAULT
) {
155 $this->_mimeType
= $value;
160 * Get indexed filename (using image index)
164 public function getIndexedFilename() {
165 $extension = strtolower($this->getMimeType());
166 $extension = explode('/', $extension);
167 $extension = $extension[1];
169 return $this->_uniqueName
. $this->getImageIndex() . '.' . $extension;
175 * @return string Hash code
177 public function getHashCode() {
179 $this->_renderingFunction
182 . parent
::getHashCode()
188 * Implement PHP __clone to create a deep clone, not just a shallow copy.
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;
196 $this->$key = $value;