/** * @param int $thumbSize * @return null|string * @throws \Exception */ public function getThumb($thumbSize = Image::SMALL_THUMB) { switch ($this->type) { case self::IMAGE_FILETYPE: $ext = $this->getExtension(); $imageId = $this->getId(); $urlPart = Image::imgPath($thumbSize, $imageId, $ext, FileService::FROM_PUBLIC); if (!file_exists($urlPart)) { $originalLocation = $this->getLocation(); $image = new \Imagick($originalLocation); $size = Image::sizeByType($thumbSize); $image->cropThumbnailImage($size['width'], $size['height']); FileService::prepareDir(FileService::PUBLIC_PATH . $urlPart); $image->writeimage(FileService::PUBLIC_PATH . $urlPart); } return $urlPart; case self::AUDIO_FILETYPE: return Audio::audioPath($this->id, $this->getExtension(), FileService::FROM_PUBLIC); case self::VIDEO_FILETYPE: return Video::videoPath($this->id, $this->getExtension(), FileService::FROM_PUBLIC); default: } return null; }