public function actionServeImage() { $preset = $_GET['preset']; list($width, $height) = $this->resolvePreset($preset); $image = File::getByName($_GET['name']); if (isset($image) && is_file($image->path)) { $presetFolder = $image->getPresetFolder($preset); $fileCachePath = $presetFolder . $image->filename; FileHelper::createDirectory($presetFolder); if ($preset == 'editor') { copy($image->path, $fileCachePath); } else { Image::getImagine()->open($image->path)->thumbnail(new \Imagine\Image\Box($width, $height))->save($fileCachePath); } header('Content-type: ' . mime_content_type($fileCachePath)); readfile($fileCachePath); exit; } }
public function afterSave($insert, $changedAttributes) { FileHelper::createDirectory($this->uploadFolder, 0755); $this->resource->saveAs($this->path); parent::afterSave($insert, $changedAttributes); }