Example #1
0
 /**
  * Resizes image to fit into a square container
  *
  * Manual: http://code.google.com/p/zend-image/wiki/Quick_Start
  * 
  * @param  int $imagePath Original image path
  * @param  int $newPath Transformed image path
  * @param  int $fitInDimension Container size (square) the transformed image should fit in
  * @return boolean True on save success, false on failure
  */
 public static function resizeImage($imagePath, $newPath, $fitInDimensionX, $fitInDimensionY = 0)
 {
     if (substr($imagePath, 0, 1) != '/') {
         $imagePath = '/' . $imagePath;
     }
     if (substr($newPath, 0, 1) != '/') {
         $newPath = '/' . $newPath;
     }
     if ($fitInDimensionY == 0) {
         $fitInDimensionY = $fitInDimensionX;
     }
     $img = new Zend_Image(Admin_View_Helper_ImageControls::_getPublicPath() . $imagePath, new Zend_Image_Driver_Gd());
     $transformed = new Zend_Image_Transform($img);
     $resized = $transformed->fitIn($fitInDimensionX, $fitInDimensionY);
     $resized->save(Admin_View_Helper_ImageControls::_getPublicPath() . $newPath);
     return file_exists(Admin_View_Helper_ImageControls::_getPublicPath() . $newPath);
 }
 public function whatIDoAction()
 {
     $form = new Admin_Form_WhatIDoForm();
     $whatIDo = $this->_contacts->getWhatIDoByID();
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             // update
             if ($form->Image->isUploaded()) {
                 $form->Image->receive();
                 $path = "img/profile/WhatIDo.jpg";
                 Admin_View_Helper_ImageControls::resizeImage($path, $path, 200, 300);
                 $formData['ImageUpdateTime'] = Site_View_Helper_Date::formatDate();
                 $whatIDo->ImageUpdateTime = Site_View_Helper_Date::formatDate();
             }
             $this->_contacts->updateWhatIDo($formData);
         } else {
             $form->populate($formData);
         }
     } else {
         $data = $whatIDo->toArray();
         $form->populate($data);
     }
     $this->view->whatIDo = $whatIDo;
     $this->view->form = $form;
 }