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 findTabbarMore() { $datas = array('option_id' => 'more_items', 'value_id' => 'more_items', 'code' => 'tabbar_more', 'name' => $this->getApplication()->getTabbarMoreName(), 'tabbar_name' => $this->getApplication()->getTabbarMoreName(), 'is_ajax' => 0, 'price' => 0.0, 'is_active' => 1); $datas['desktop_uri'] = 'application/customization_features_tabbar_more/'; $this->setData($datas)->setId('more_items'); $this->setIconUrl(Media_Model_Library_Image::getImagePathTo('/tabbar/more_items.png')); $this->setBaseIconUrl(Media_Model_Library_Image::getBaseImagePathTo('/tabbar/more_items.png')); return $this; }
public function colorize1Action() { if ($this->getRequest()->getParam('id') || $this->getRequest()->getParam('url') || $this->getRequest()->getParam('path') and $color = $this->getRequest()->getParam('color')) { $cache = Zend_Registry::get('cache'); $id = $this->getRequest()->getParam('id'); // $cache_id = 'colorized_image_'.sha1($id.':'.$color); // $cache->remove($cache_id); // $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('colorized_image'));die; // if (($img = $cache->load($cache_id)) === false) { if ($this->getRequest()->getParam('id')) { $image = new Media_Model_Library_Image(); $image->find($id); $path = $image->getLink(); $image_path = Media_Model_Library_Image::getBaseImagePathTo($path); } else { if ($this->getRequest()->getParam('url')) { $url = $this->getRequest()->getParam('url'); $path = Core_Model_Directory::getTmpDirectory(true) . '/' . $url; $image_path = $path; } else { if ($this->getRequest()->getParam('path')) { $path = $this->getRequest()->getParam('path'); $path = Core_Model_Directory::getBasePathTo(base64_decode($path)); if (!is_file($path)) { die; } $image_path = $path; } } } $color = $color; $rgb = $this->toRgb($color); list($width, $height) = getimagesize($image_path); $new_img = imagecreatefromstring(file_get_contents($image_path)); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $colors = imagecolorat($new_img, $x, $y); $current_rgb = imagecolorsforindex($new_img, $colors); $color = imagecolorallocatealpha($new_img, $rgb['red'], $rgb['green'], $rgb['blue'], $current_rgb['alpha']); imagesetpixel($new_img, $x, $y, $color); } } imagesavealpha($new_img, true); ob_start(); @imagepng($new_img); $contents = ob_get_contents(); ob_end_clean(); imagedestroy($new_img); // $cache->save($contents, $cache_id, array('colorized_image')); $img = $contents; // } // Zend_Debug::dump($img); die; $this->getResponse()->setHeader('Content-Type', 'image/png'); $this->getLayout()->setHtml($img); die; } }
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, $image->getAppId()); } 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 uploadiconAction() { if ($datas = $this->getRequest()->getPost()) { try { $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); if (!empty($file)) { $option_value = new Application_Model_Option_Value(); $option_value->find($datas['option_id']); $lib = new Media_Model_Library(); $lib->find($option_value->getLibraryId()); $library_name = $lib->getName(); $formated_library_name = Core_Model_Lib_String::format($library_name, true); $base_lib_path = Media_Model_Library_Image::getBaseImagePathTo($formated_library_name); $files = Core_Model_Directory::getTmpDirectory(true) . '/' . $file; $CanBeColorized = $datas['is_colorized'] == 'true' ? 1 : 0; if (!is_dir($base_lib_path)) { mkdir($base_lib_path, 0777, true); } if (!copy($files, $base_lib_path . '/' . $file)) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $icon_lib = new Media_Model_Library_Image(); $icon_lib->setLibraryId($option_value->getLibraryId())->setLink('/' . $formated_library_name . '/' . $file)->setOptionId($option_value->getOptionId())->setAdminId($this->getSession()->getAdmin()->getId())->setCanBeColorized($CanBeColorized)->setPosition(0)->save(); $option_value->setIcon('/' . $formated_library_name . '/' . $file)->setIconId($icon_lib->getImageId())->save(); $icon_saved = $this->setIcon($icon_lib->getImageId(), $datas['option_id']); // Charge l'option_value $option_value = new Application_Model_Option_Value(); $option_value->find($datas['option_id']); $icon_color = $this->getApplication()->getDesignBlock('tabbar')->getImageColor(); $html = array('success' => 1, 'file' => '/' . $formated_library_name . '/' . $file, 'icon_id' => $icon_lib->getImageId(), 'colorizable' => $CanBeColorized, 'icon_url' => Media_Model_Library_Image::getImagePathTo($formated_library_name . '/' . $file), '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'], 'message' => '', 'message_button' => 1, 'message_loader' => 1); } } } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }