4 * PHPExcel_Worksheet_MemoryDrawing
6 * Copyright (c) 2006 - 2015 PHPExcel
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * @package PHPExcel_Worksheet
24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version ##VERSION##, ##DATE##
28 class PHPExcel_Worksheet_MemoryDrawing
extends PHPExcel_Worksheet_BaseDrawing
implements PHPExcel_IComparable
30 /* Rendering functions */
31 const RENDERING_DEFAULT
= 'imagepng';
32 const RENDERING_PNG
= 'imagepng';
33 const RENDERING_GIF
= 'imagegif';
34 const RENDERING_JPEG
= 'imagejpeg';
37 const MIMETYPE_DEFAULT
= 'image/png';
38 const MIMETYPE_PNG
= 'image/png';
39 const MIMETYPE_GIF
= 'image/gif';
40 const MIMETYPE_JPEG
= 'image/jpeg';
47 private $imageResource;
54 private $renderingFunction;
71 * Create a new PHPExcel_Worksheet_MemoryDrawing
73 public function __construct()
76 $this->imageResource
= null;
77 $this->renderingFunction
= self
::RENDERING_DEFAULT
;
78 $this->mimeType
= self
::MIMETYPE_DEFAULT
;
79 $this->uniqueName
= md5(rand(0, 9999). time() . rand(0, 9999));
82 parent
::__construct();
90 public function getImageResource()
92 return $this->imageResource
;
98 * @param $value resource
99 * @return PHPExcel_Worksheet_MemoryDrawing
101 public function setImageResource($value = null)
103 $this->imageResource
= $value;
105 if (!is_null($this->imageResource
)) {
107 $this->width
= imagesx($this->imageResource
);
108 $this->height
= imagesy($this->imageResource
);
114 * Get rendering function
118 public function getRenderingFunction()
120 return $this->renderingFunction
;
124 * Set rendering function
126 * @param string $value
127 * @return PHPExcel_Worksheet_MemoryDrawing
129 public function setRenderingFunction($value = PHPExcel_Worksheet_MemoryDrawing
::RENDERING_DEFAULT
)
131 $this->renderingFunction
= $value;
140 public function getMimeType()
142 return $this->mimeType
;
148 * @param string $value
149 * @return PHPExcel_Worksheet_MemoryDrawing
151 public function setMimeType($value = PHPExcel_Worksheet_MemoryDrawing
::MIMETYPE_DEFAULT
)
153 $this->mimeType
= $value;
158 * Get indexed filename (using image index)
162 public function getIndexedFilename()
164 $extension = strtolower($this->getMimeType());
165 $extension = explode('/', $extension);
166 $extension = $extension[1];
168 return $this->uniqueName
. $this->getImageIndex() . '.' . $extension;
174 * @return string Hash code
176 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()
192 $vars = get_object_vars($this);
193 foreach ($vars as $key => $value) {
194 if (is_object($value)) {
195 $this->$key = clone $value;
197 $this->$key = $value;