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); } }
protected 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, $image->getAppId()); } 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 deleteiconAction() { if ($datas = $this->getRequest()->getPost()) { try { $icon = new Media_Model_Library_Image(); $icon->find($datas['icon_id']); if ($icon->getAppId()) { $icon->delete(); } else { throw new Exception($this->_("You may not delete a library icon")); } $html = array('success' => 1); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->_sendHtml($html); } }