/** * 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; }
/** * Process elements value from request * * @return */ public function result() { $cogear = getInstance(); $file = new Upload_File($this->name, $this->getAttributes(), $this->validators->findByValue('Required')); if ($value = $file->upload()) { $this->is_fetched = TRUE; $this->value = $value; } else { $this->errors = $file->errors; } return $this->value; }
/** * (non-PHPdoc) * @see Upload_File::upload() */ public function upload(array $data, $path, $formUpload = true) { $data = parent::upload($data, $path, $formUpload); if (!empty($data) && !empty($this->_config['sizes'])) { foreach ($this->_config['sizes'] as $name => $xy) { $ext = File::getExt($data['path']); $replace = '-' . $name . $ext; $newName = str_replace($ext, $replace, $data['path']); if ($this->_config['thumb_types'][$name] == 'crop') { Image_Resize::resize($data['path'], $xy[0], $xy[1], $newName, true, true); } else { Image_Resize::resize($data['path'], $xy[0], $xy[1], $newName, true, false); } if ($name == 'icon') { $data['thumb'] = $newName; } } } return $data; }