當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Thumbnail::generate方法代碼示例

本文整理匯總了PHP中Thumbnail::generate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Thumbnail::generate方法的具體用法?PHP Thumbnail::generate怎麽用?PHP Thumbnail::generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Thumbnail的用法示例。


在下文中一共展示了Thumbnail::generate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionGenerate

 /**
  * 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;
 }
開發者ID:Tebro,項目名稱:xbmc-video-server,代碼行數:21,代碼來源:ThumbnailController.php

示例2: processGetFile

 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();
     }
 }
開發者ID:mobas,項目名稱:mollify,代碼行數:44,代碼來源:FilesystemServices.class.php

示例3: executeThumbs

 /**
 * 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;
 }
開發者ID:morganney,項目名稱:livewire,代碼行數:46,代碼來源:actions.class.php


注:本文中的Thumbnail::generate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。