/**
  * Action - image
  * display images in the predetermined size or in the natural size
  *
  * Access to the action is possible in the following paths:
  * - /utility/image
  *
  * @return void
  */
 public function imageAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $username = $request->getQuery('username');
     $id = (int) $request->getQuery('id');
     $w = (int) $request->getQuery('w');
     $h = (int) $request->getQuery('h');
     $hash = $request->getQuery('hash');
     $realHash = Default_Model_DbTable_BlogPostImage::GetImageHash($id, $w, $h);
     // disable autorendering since we're outputting an image
     $this->_helper->viewRenderer->setNoRender();
     $image = new Default_Model_DbTable_BlogPostImage($this->db);
     if ($hash != $realHash || !$image->load($id)) {
         // image not found
         $response->setHttpResponseCode(404);
         return;
     }
     try {
         $fullpath = $image->createThumbnail($w, $h, $username);
     } catch (Exception $ex) {
         $fullpath = $image->getFullPath($username);
     }
     $info = getImageSize($fullpath);
     $response->setHeader('content-type', $info['mime']);
     $response->setHeader('content-length', filesize($fullpath));
     echo file_get_contents($fullpath);
 }
/**
 * Get an image file
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_imagefilename($params, $smarty)
{
    if (!isset($params['id'])) {
        $params['id'] = 0;
    }
    if (!isset($params['w'])) {
        $params['w'] = 0;
    }
    if (!isset($params['w'])) {
        $params['h'] = 0;
    }
    require_once $smarty->_get_plugin_filepath('function', 'geturl');
    $hash = Default_Model_DbTable_BlogPostImage::GetImageHash($params['id'], $params['w'], $params['h']);
    $options = array('controller' => 'utility', 'action' => 'image');
    return sprintf('%s?username=%s&id=%d&w=%d&h=%d&hash=%s', smarty_function_geturl($options, $smarty), $params['username'], $params['id'], $params['w'], $params['h'], $hash);
}