/** * Logic to deal with uploading the image file and generating thumbnails according to * what has been specified in the $thumbnails array. * * @param Validation $validation * @param Jelly_Model $model * @param string $field * @return bool * @uses Image::factory */ public function _upload(Validation $validation, $model, $field) { if (!parent::_upload($validation, $model, $field)) { // Couldn't save the original untouched return FALSE; } $file = $validation[$field]; //no need upload if post helper isset if (!empty($_POST[self::$post_file_helper_prefix . $this->name])) { $this->_filename = $_POST[self::$post_file_helper_prefix . $this->name]; return TRUE; } // Set the filename and the source $filename = $this->_filename; $source = $filename; if ($model->changed($field)) { // Process thumbnails foreach ($this->thumbnails as $thumbnail) { if (!isset($thumbnail['path'])) { // Set the thumbnail path to the original's path if not set $thumbnail['path'] = $this->path; } $filename = explode('/', $filename); $filename = end($filename); // Set the destination $destination = $thumbnail['path'] . $thumbnail['prefix'] . $filename; // Delete old file if necessary $this->_delete_old_file($thumbnail['prefix'] . $model->original($field), $thumbnail['path']); // Set thumb $source = realpath(ltrim($this->_filename, '/')); $thumb = Image::factory($source, $this->driver); // Process thumbnail transformations $thumb = $this->_transform($thumb, $thumbnail['transformations']); // Save the thumbnail $thumb->save($destination, $thumbnail['quality']); } } if (count($this->transformations) > 0 && !empty($source)) { $source = realpath(ltrim($this->_filename, '/')); // Set image $image = Image::factory($source, $this->driver); // Process image transformations $image = $this->_transform($image, $this->transformations); // Save the image $image->save($source, $this->quality); } return TRUE; }