ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
MemoryDrawing.php
Go to the documentation of this file.
1 <?php
37 {
38  /* Rendering functions */
39  const RENDERING_DEFAULT = 'imagepng';
40  const RENDERING_PNG = 'imagepng';
41  const RENDERING_GIF = 'imagegif';
42  const RENDERING_JPEG = 'imagejpeg';
43 
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';
49 
55  private $_imageResource;
56 
63 
69  private $_mimeType;
70 
76  private $_uniqueName;
77 
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));
88 
89  // Initialize parent
91  }
92 
98  public function getImageResource() {
99  return $this->_imageResource;
100  }
101 
108  public function setImageResource($value = null) {
109  $this->_imageResource = $value;
110 
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  }
118 
124  public function getRenderingFunction() {
126  }
127 
135  $this->_renderingFunction = $value;
136  return $this;
137  }
138 
144  public function getMimeType() {
145  return $this->_mimeType;
146  }
147 
155  $this->_mimeType = $value;
156  return $this;
157  }
158 
164  public function getIndexedFilename() {
165  $extension = strtolower($this->getMimeType());
166  $extension = explode('/', $extension);
167  $extension = $extension[1];
168 
169  return $this->_uniqueName . $this->getImageIndex() . '.' . $extension;
170  }
171 
177  public function getHashCode() {
178  return md5(
179  $this->_renderingFunction
180  . $this->_mimeType
181  . $this->_uniqueName
182  . parent::getHashCode()
183  . __CLASS__
184  );
185  }
186 
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 }