/**
  * Edit image
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $do_rotate = $request->getParam('rotate');
     $do_skip = $request->getParam('skip');
     $Profiles = new Application_Model_Profiles();
     $profile = $Profiles->getProfileRow($this->profile_name, true, true);
     if (!$profile) {
         $this->redirect('');
     }
     $extension = strtolower(pathinfo(TMP_PATH . '/' . $this->image_name, PATHINFO_EXTENSION));
     if ($request->isPost() || $do_skip) {
         if ($do_skip) {
             // skip editing and use the full image
             Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $this->image_name, TMP_PATH . '/' . $this->image_name, $this->target_x, $this->target_y, false);
         } else {
             $x = intval($_POST['x']);
             $y = intval($_POST['y']);
             $w = intval($_POST['w']);
             $h = intval($_POST['h']);
             if ($x + $y + $w + $h == 0) {
                 $this->redirect('');
             }
             Application_Plugin_ImageLib::crop(TMP_PATH . '/' . $this->image_name, $x, $y, $w, $h, $this->target_x, $this->target_y);
         }
         $Storage = new Application_Model_Storage();
         $StorageAdapter = $Storage->getAdapter();
         // delete old file
         if (strstr($profile->{$this->db_field}, 'default') === false) {
             $StorageAdapter->deleteFileFromStorage($profile->{$this->db_field}, $this->image_type);
         }
         $new_filename = $StorageAdapter->moveFileToStorage($this->view->image, $this->image_type);
         $profile->{$this->db_field} = $new_filename;
         $profile->save();
         Application_Plugin_Alerts::success($this->view->translate('Image saved'));
         // kill tmp session
         $session = new Zend_Session_Namespace('Default');
         $session->pass_params = false;
         // refresh user session in case profile picture is updated
         Zend_Auth::getInstance()->getStorage()->write($Profiles->getProfileRowObject());
         // go back
         $this->redirect($this->callback);
     } elseif ($do_rotate) {
         Application_Plugin_ImageLib::rotate(TMP_PATH . '/' . $this->image_name);
     }
 }
Beispiel #2
0
 /**
  * Rotate image
  */
 public function rotateImage($image_id)
 {
     $image = $this->getImage($image_id);
     // check if image exists and this is the owner
     if (!$image || !Zend_Auth::getInstance()->hasIdentity() || $image['data']['uploaded_by'] != Zend_Auth::getInstance()->getIdentity()->id) {
         return false;
     }
     $file_name = $image['data']['file_name'];
     $tmp_file_name = 'edit_' . $file_name;
     $Storage = new Application_Model_Storage();
     $StorageAdapter = $Storage->getAdapter();
     $StorageAdapter->getFileFromStorage($file_name, $tmp_file_name, 'posts');
     $ret = Application_Plugin_ImageLib::rotate(TMP_PATH . '/' . $tmp_file_name);
     if ($ret) {
         $StorageAdapter->deleteFileFromStorage($file_name, 'posts');
         $new_filename = $StorageAdapter->moveFileToStorage($tmp_file_name, 'posts');
         $this->updateField($image['data']['id'], 'file_name', $new_filename);
     }
     return $new_filename;
 }