public function makeThumb($photo, $size = 'small') { if (!$photo) { return false; } $sizes = $this->sizes; $absolutePath = $this->bcms->home_dir; $sourceFilePath = $absolutePath . $photo; $sourceFileName = basename($sourceFilePath); if (!file_exists($sourceFilePath)) { $this->bcms->flash('error', 'Check filename, system can not access it'); return false; } $targetDir = dirname($sourceFilePath) . '/' . $size; $targetFilePath = $targetDir . '/' . $sourceFileName; $targetFileRelativePath = dirname($photo) . '/' . $size . '/' . $sourceFileName; try { $img = new \BCMS\SimpleImage($sourceFilePath); //Check dir is exists if (!file_exists($targetDir)) { if (!mkdir($targetDir)) { $this->bcms->flash('error', 'Can not create folder ' . $targetDir); } } elseif (!is_writable($targetDir)) { $this->bcms->flash('error', $targetDir . ' is not writeable.'); } if ($size === 'small') { //$img->smart_crop($sizes[$size])->save($targetFilePath); $img->best_fit($sizes[$size], $sizes[$size])->save($targetFilePath); } elseif ($size === 'medium') { $img->best_fit($sizes[$size], $sizes[$size])->save($targetFilePath); } elseif ($size === 'medium_square') { $img->smart_crop($sizes[$size])->save($targetFilePath); } return $targetFileRelativePath; } catch (Exception $e) { $this->bcms->flash('error', $e->getMessage()); } }