uniqueName = \md5(\rand(0, 9999) . \time() . \rand(0, 9999)); } /** * Get image resource. * * @return resource */ public function getImageResource() { return $this->imageResource; } /** * Set image resource. * * @param resource $value * * @return $this */ public function setImageResource($value = null) { $this->imageResource = $value; if (!\is_null($this->imageResource)) { // Get width/height $this->width = \imagesx($this->imageResource); $this->height = \imagesy($this->imageResource); } return $this; } /** * Get rendering function. * * @return string */ public function getRenderingFunction() { return $this->renderingFunction; } /** * Set rendering function. * * @param string $value * * @return $this */ public function setRenderingFunction($value = self::RENDERING_DEFAULT) { $this->renderingFunction = $value; return $this; } /** * Get mime type. */ public function getMimeType(): string { return $this->mimeType; } /** * Set mime type. * * @param string $value * * @return $this */ public function setMimeType($value = self::MIMETYPE_DEFAULT) { $this->mimeType = $value; return $this; } public function getContents(): string { \ob_start(); if (self::MIMETYPE_DEFAULT === $this->getMimeType()) { \imagealphablending($this->getImageResource(), false); \imagesavealpha($this->getImageResource(), true); } \call_user_func($this->getRenderingFunction(), $this->getImageResource()); $imageContents = \ob_get_contents(); \ob_end_clean(); return $imageContents; } public function getExtension(): string { $extension = \strtolower($this->getMimeType()); $extension = \explode('/', $extension); $extension = $extension[1]; return $extension; } public function getIndexedFilename(): string { return $this->uniqueName . $this->getImageIndex() . '.' . $this->getExtension(); } /** * @var string */ protected $path; /** * Get Path. */ public function getPath(): string { return $this->path; } public function setPath(string $path): self { $this->path = $path; return $this; } }