本文整理汇总了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;
}
示例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();
}
}
示例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;
}