本文整理汇总了PHP中Intervention\Image\Facades\Image::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::cache方法的具体用法?PHP Image::cache怎么用?PHP Image::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Facades\Image
的用法示例。
在下文中一共展示了Image::cache方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
/**
* Display the specified resource.
*
* @param $image_slug
* @param int $width
* @return Response
*/
public function show($image_slug, $width = 500)
{
$currentUser = $this->getUser();
//$size = (Input::get('size')? (is_numeric(Input::get('size'))? Input::get('size') : 500) : 500);//TODO: Extract this to global config
$comicImage = ComicImage::where('image_slug', '=', $image_slug)->first();
if (!$comicImage) {
return $this->respondNotFound(['title' => 'Image Not Found', 'detail' => 'Image Not Found', 'status' => 404, 'code' => '']);
}
$userCbaIds = $currentUser->comics()->lists('comic_book_archive_id')->all();
$comicCbaIds = $comicImage->comicBookArchives()->lists('comic_book_archive_id')->all();
foreach ($comicCbaIds as $comicCbaId) {
if (!in_array($comicCbaId, $userCbaIds)) {
return $this->respondNotFound(['title' => 'Image Not Found', 'detail' => 'Image Not Found', 'status' => 404, 'code' => '']);
}
}
$img = Image::make($comicImage->image_url);
$imgCache = Image::cache(function ($image) use($img, $width) {
$image->make($img)->interlace()->resize(null, $width, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}, 60, true);
//dd($imgCache->response());
return $imgCache->response();
}
示例2: resize
public function resize($width, $height)
{
$imageCache = Image::cache(function ($image) use($width, $height) {
$image->make($this->getFilePath())->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
});
return $imageCache;
}
示例3: resize
public function resize($id, $size = null)
{
$asset = Asset::find($id);
if ($asset == null) {
return '';
}
$url = $asset->relativeURL();
$w = null;
$h = null;
$s = null;
if ($size != null) {
preg_match('/w(\\d+)/', $size, $wMatch);
preg_match('/h(\\d+)/', $size, $hMatch);
preg_match('/s(\\d+)/', $size, $sMatch);
if (count($wMatch) >= 2) {
$w = $wMatch[1];
}
if (count($hMatch) >= 2) {
$h = $hMatch[1];
}
if (count($sMatch) >= 2) {
$s = $sMatch[1];
}
}
$img = Image::cache(function ($image) use($url, $w, $h, $s) {
$image->make($url);
if ($s != null) {
$image->resize($s, null, function ($constraint) {
$constraint->aspectRatio();
})->crop($s, $s);
} else {
if ($w != null || $h != null) {
$image->resize($w, $h, function ($constraint) {
$constraint->aspectRatio();
});
}
}
return $image;
});
$file = new \Symfony\Component\HttpFoundation\File\File($url);
$mime = $file->getMimeType();
return Response::make($img, 200, array('Content-Type' => $mime));
}
示例4: show
public function show(Request $request, $path)
{
$path = public_path($path);
$size = explode('x', $request->size);
$options = $request->get('op', null);
$img = Image::cache(function ($image) use($path, $size, $options) {
switch ($options) {
case 'c':
# code...
break;
case 'r':
$image->make($path)->resize($size[0], $size[1], function ($c) {
$c->aspectRatio();
})->encode('png', 80);
break;
default:
$image->make($path)->fit($size[0], $size[1])->encode('png', 80);
break;
}
}, 43200, true);
return $img->response('png');
}
示例5: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id, $param1 = null, $param2 = null)
{
//Get a specific item
$entry = Contentful::entries()->limitByType('2wKn6yEnZewu2SCCkus4as')->includeLinks(10)->get();
/**
* get youtube video ID from URL
*
* @param string $url
* @return string Youtube video id or FALSE if none found.
*/
function youtube_id_from_url($url)
{
$pattern = '%^# Match any youtube URL
(?:https?://)? # Optional scheme. Either http or https
(?:www\\.)? # Optional www subdomain
(?: # Group host alternatives
youtu\\.be/ # Either youtu.be,
| youtube\\.com # or youtube.com
(?: # Group path alternatives
/embed/ # Either /embed/
| /v/ # or /v/
| /watch\\?v= # or /watch\\?v=
) # End path alternatives.
) # End host alternatives.
([\\w-]{10,12}) # Allow 10-12 for 11 char youtube id.
$%x';
$result = preg_match($pattern, $url, $matches);
if (false !== $result) {
return $matches[1];
}
return false;
}
foreach ($entry['items'] as $key => $post) {
if ($post['fields']['slug'] == $id) {
//global $post;
//content
$blog['title'] = $post['fields']['title'];
$blog['body'] = Markdown::parse($post['fields']['body']);
$blog['slug'] = $post['fields']['slug'];
//media
$blog['imageId'] = $post['fields']['featuredImage']['sys']['id'];
if (isset($post['fields']['gallery'])) {
//Prepare the gallery of images
foreach ($post['fields']['gallery'] as $keyId => $imgId) {
$id = $imgId['sys']['id'];
foreach ($entry['includes']['Asset'] as $key => $asset) {
if ($id == $asset['sys']['id']) {
$gallery[$key]['id'] = $asset['sys']['id'];
$gallery[$key]['imageUrl'] = $asset['fields']['file']['url'];
}
}
}
$blog['gallery'] = $gallery;
}
if (isset($post['fields']['location'])) {
$blog['location'] = $post['fields']['location'];
}
if (isset($post['fields']['video3'])) {
$blog['video'] = youtube_id_from_url($post['fields']['video3']);
}
if (isset($post['fields']['image'])) {
$blog['image'] = Image::cache(function ($image) use($post) {
$image->make($post['fields']['image'])->encode('data-url');
}, null, false);
}
//metadeta
$blog['createdAt'] = $post['sys']['createdAt'];
}
}
//get a specific asset
$assets = Contentful::assets()->where('sys.id', '=', $blog['imageId'])->get();
//setting the width of the image on the fly!
$blog['imageUrl'] = Image::cache(function ($image) use($assets) {
$image->make('http:' . $assets['items'][0]['fields']['file']['url'] . '?' . 'w=400&fm=jpg')->greyscale()->encode('data-url');
}, null, false);
$params = display($param1, $param2);
$params['blog'] = $blog;
return view('blog.item')->with($params);
}