/**
  * Generates a thumbnail for the specified image path and size, then serves 
  * it to the browser. The next time the same thumbnail is rendered its URL 
  * will point to the generated image instead of this action.
  * @see Thumbnail
  * @param string $path the thumbnail path
  * @param int $size the thumbnail size
  * @throws PageNotFoundException if the image could not be generated
  */
 public function actionGenerate($path, $size)
 {
     $thumbnail = new Thumbnail($path, $size);
     $thumbnail->generate();
     $path = $thumbnail->getPath();
     if ($path === false) {
         throw new PageNotFoundException();
     }
     header('Content-Type: ' . CFileHelper::getMimeType($path));
     readfile($path);
     exit;
 }
 private function processGetFile($item)
 {
     if (count($this->path) == 1) {
         $mobile = ($this->env->request()->hasParam("m") and strcmp($this->env->request()->param("m"), "1") == 0);
         if (isset($_SERVER['HTTP_RANGE'])) {
             $this->env->filesystem()->download($item, $mobile, $_SERVER['HTTP_RANGE']);
         } else {
             $this->env->filesystem()->download($item, $mobile);
         }
         return;
     }
     switch (strtolower($this->path[1])) {
         case 'thumbnail':
             if (!$item->isFile()) {
                 throw $this->invalidRequestException();
             }
             if (!in_array(strtolower($item->extension()), array("gif", "png", "jpg", "jpeg"))) {
                 throw $this->invalidRequestException();
             }
             if ($this->env->settings()->setting("enable_thumbnails")) {
                 require_once "include/Thumbnail.class.php";
                 $maxWidth = 400;
                 $maxHeight = 400;
                 if ($this->env->request()->hasParam("mw") and $this->env->request()->hasParam("mh")) {
                     $maxWidth = intval($this->env->request()->param("mw"));
                     $maxHeight = intval($this->env->request()->param("mh"));
                 }
                 $t = new Thumbnail();
                 if ($t->generate($item, $maxWidth, $maxHeight)) {
                     die;
                 }
             }
             $this->env->filesystem()->view($item);
             return;
         case 'view':
             $this->env->filesystem()->view($item);
             die;
         case 'details':
             $this->response()->success($this->env->filesystem()->details($item));
             break;
         default:
             throw $this->invalidRequestException();
     }
 }
Beispiel #3
0
 /**
 * Method used to dynamically generate thumbnails for pagination lists.
 * Currently not in use since all thumbnails are stored on disk now.
 * Below is the old markup used in _basicListDisplay template that calls this action:
 * (to reuse this, modify the method to check for the disk on file first, then create 
 * thumbnail if necessary)
 * <div class='l'>
 			<table>
 				<tr><td><?php echo image_tag(url_for("@thumbs?img_file={$part['img_file']}&sf_format={$part['img_mime']}"), array('alt' => "{$part['part_no']}")) ?></td></tr>
 			</table>
 		</div>
 * @param sfWebRequest $request
 */
 public function executeThumbs(sfWebRequest $request)
 {
     // NOTE: All images are now files on disk (6/15/2010)
     $this->setLayout(false);
     $response = $this->getResponse();
     $response->clearHttpHeaders();
     $etag = '"' . md5($request->getParameter('img_file')) . '"';
     $response->setHttpHeader('Etag', $etag);
     if ($request->getHttpHeader('IF_NONE_MATCH') == $etag) {
         $response->setStatusCode(304, 'Not Modified');
     } else {
         // GD library uses jpeg not jpg.
         $mime_type = $request->getParameter('sf_format') == 'jpg' ? 'jpeg' : $request->getParameter('sf_format');
         $response->setContentType("image/{$mime_type}");
         $response->sendHttpHeaders();
         $thumb = new Thumbnail($request->getParameter('img_file'), $mime_type);
         try {
             if ($binary = $thumb->generate()) {
                 $response->setContent($binary);
             } else {
                 $response->setContentType('image/png');
                 $response->setContent(readfile(sfConfig::get('app_thumbs_dir') . 'default-trans.png'));
             }
         } catch (GDErrorException $gde) {
             $response->setContentType('image/png');
             $response->setContent(readfile(sfConfig::get('app_thumbs_dir') . 'default-trans.png'));
         }
         $thumb->freeMemoryResources();
         $response->sendHttpHeaders();
         $response->sendContent();
     }
     return sfView::HEADER_ONLY;
 }