Exemple #1
0
 public function getColorizedImage($image_id, $color)
 {
     $color = str_replace('#', '', $color);
     $id = md5(implode('+', array($image_id, $color)));
     $url = '';
     $image = new Media_Model_Library_Image();
     if (is_numeric($image_id)) {
         $image->find($image_id);
         if (!$image->getId()) {
             return $url;
         }
         if (!$image->getCanBeColorized()) {
             $color = null;
         }
         $path = $image->getLink();
         $path = Media_Model_Library_Image::getBaseImagePathTo($path);
     } else {
         if (!Zend_Uri::check($image_id) and stripos($image_id, Core_Model_Directory::getBasePathTo()) === false) {
             $path = Core_Model_Directory::getBasePathTo($image_id);
         } else {
             $path = $image_id;
         }
     }
     try {
         $image = new Core_Model_Lib_Image();
         $image->setId($id)->setPath($path)->setColor($color)->colorize();
         $url = $image->getUrl();
     } catch (Exception $e) {
         $url = '';
     }
     return $url;
 }
 public function colorizeAction()
 {
     if ($this->getRequest()->getParam('id') || $this->getRequest()->getParam('url') || $this->getRequest()->getParam('path') and $color = $this->getRequest()->getParam('color')) {
         $params = array('id', 'url', 'path', 'color');
         $path = '';
         foreach ($params as $param) {
             $id[] = $this->getRequest()->getParam($param);
         }
         $id = md5(implode('+', $id));
         if ($image_id = $this->getRequest()->getParam('id')) {
             $image = new Media_Model_Library_Image();
             $image->find($image_id);
             if (!$image->getCanBeColorized()) {
                 $color = null;
             }
             $path = $image->getLink();
             $path = Media_Model_Library_Image::getBaseImagePathTo($path);
         } else {
             if ($url = $this->getRequest()->getParam('url')) {
                 $path = Core_Model_Directory::getTmpDirectory(true) . '/' . $url;
             } else {
                 if ($path = $this->getRequest()->getParam('path')) {
                     $path = base64_decode($path);
                     if (!Zend_Uri::check($path)) {
                         $path = Core_Model_Directory::getBasePathTo($path);
                         if (!is_file($path)) {
                             die;
                         }
                     }
                 }
             }
         }
         $image = new Core_Model_Lib_Image();
         $image->setId($id)->setPath($path)->setColor($color)->colorize();
         ob_start();
         @imagepng($image->getResources());
         $contents = ob_get_contents();
         ob_end_clean();
         imagedestroy($image->getResources());
         $this->getResponse()->setHeader('Content-Type', 'image/png');
         $this->getLayout()->setHtml($contents);
     }
 }
 public function seticonAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             // Charge l'icône
             $icon = new Media_Model_Library_Image();
             $icon->find($datas['icon_id']);
             // Test si l'option_value_id est passé en paramètre
             if (empty($datas['option_value_id'])) {
                 throw new Exception($this->_('An error occurred while saving'));
             }
             if (empty($datas['icon_id'])) {
                 throw new Exception($this->_('An error occurred while saving. The selected icon is not valid.'));
             }
             $icon_saved = $this->setIcon($datas['icon_id'], $datas['option_value_id']);
             if (!empty($icon_saved)) {
                 // Charge l'option_value
                 $option_value = new Application_Model_Option_Value();
                 $option_value->find($datas['option_value_id']);
                 $icon_color = $this->getApplication()->getBlock('tabbar')->getImageColor();
                 $icon_url = $icon_saved['icon_url'];
                 if ($icon->getCanBeColorized()) {
                     $icon_url = $this->_getColorizedImage($icon->getImageId(), $option_value->getIconColor());
                 }
                 $html = array('success' => 1, 'icon_id' => $icon->getId(), 'icon_url' => $icon_url, 'colored_icon_url' => $this->getUrl('template/block/colorize', array('id' => $option_value->getIconId(), 'color' => str_replace('#', '', $icon_color))), 'colored_header_icon_url' => $icon_saved['colored_header_icon_url']);
             } else {
                 throw new Exception($this->_('An error occurred while saving'));
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->_sendHtml($html);
     }
 }