/** * Upload * * @return boolean */ public function upload() { if ($this->options->preset && ($preset = config('image.presets.' . $this->options->preset))) { $preset->options && $this->options->mix($preset->options); } if ($result = parent::upload()) { $this->getInfo(); $image = new Image($this->file->path); if ($this->options->preset) { $preset = new Image_Preset($this->options->preset); if ($preset->load()) { $preset->image($image)->process(); } } else { // Resize $this->options->resize && $image->resize($this->options->resize); // Crop $this->options->crop && $image->crop($this->options->crop); // Size & Crop $this->options->sizecrop && $image->sizecrop($this->options->sizecrop); // Watermark $this->options->watermark && $image->watermark($this->options->watermark); } $image->save(); return $result; } return FALSE; }
function image_preset($name, $path, $toUri = FALSE) { $preset = new Image_Preset($name); if ($preset->load()) { $image = $preset->image($path)->render(); return $toUri ? Url::toUri($image) : $image; } }
/** * Постобработка * * @param array|Core_ArrayObject */ public function postProcess($file) { $image = new Image($file->path); if ($this->options->preset) { $preset = new Image_Preset($this->options->preset); if ($preset->load()) { $preset->image($image)->process(); } } $image->save(); }
/** * Size * * @param */ public function getSizeFromString($size) { // Simple 200x200 or just 200 if (preg_match('(\\d+(x\\d+)?)', $size)) { $size = explode('x', $size); if (sizeof($size) == 1) { $size[1] = $size[0]; } return new Core_ArrayObject(array('width' => $size[0], 'height' => $size[1])); } elseif (preg_match('([\\w_-]+)', $size)) { $preset = new Image_Preset($size); if ($preset->load()) { return $this->getSizeFromString($preset->size); } } return NULL; }