本文整理汇总了PHP中Image::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::cache方法的具体用法?PHP Image::cache怎么用?PHP Image::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::cache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resizeCanvas
protected function resizeCanvas()
{
if (empty($this->path)) {
$this->image = \Image::cache(function ($image) {
return $image->canvas(800, 800, $this->bgcolor)->resizeCanvas($this->width, $this->height, $this->position, false, $this->bgcolor);
}, 10, true);
} else {
$this->image = \Image::cache(function ($image) {
return $image->make($this->destination . '/' . $this->path)->resizeCanvas($this->width, $this->height, $this->position, false, $this->bgcolor);
}, 10, true);
}
}
示例2: post_images
public function post_images()
{
$json = array();
$file = $_FILES['file'];
$module = $this->param('module', 'default');
if (!Upload::not_empty($file)) {
$this->json = json_encode($json);
return;
}
$image = ORM::factory('media')->set('module', $module)->upload($file, array('jpg', 'jpeg', 'gif', 'png'));
$json = array('id' => $image->id, 'thumb' => Image::cache($image->filename, 100, 100, Image::INVERSE), 'image' => PUBLIC_URL . $image->filename, 'title' => (string) $image->description, 'folder' => $image->module);
$this->response($json);
}
示例3: handle
/**
* Execute the job.
*
*/
public function handle()
{
foreach ($this->chunk as $pathName) {
// Generate the thumbnail as base64
$thumbnail = \Image::cache(function ($image) use($pathName) {
return $image->make($pathName)->fit(300, 200)->encode('data-url');
}, 10, false);
// Generate a unique key identifier based on time
$key = str_random();
Cache::add($key, $thumbnail, 3600);
// Fire event
event(new ThumbnailGenerated($key));
}
}
示例4: ma_get_image_on_the_fly_cached
function ma_get_image_on_the_fly_cached($asset, $w, $h, $type = 'jpg')
{
if ($asset != '' && file_exists(ma_get_image_path_from_repository($asset))) {
$dataImage = array();
$dataImage['asset'] = $asset;
$dataImage['w'] = $w;
$dataImage['h'] = $h;
$dataImage['type'] = $type;
$img = Image::cache(function ($image) use($dataImage) {
$image->make(ma_get_image_from_repository($dataImage['asset']))->fit($dataImage['w'], $dataImage['h'])->encode($dataImage['type']);
});
return 'data:image/' . $type . ';base64,' . base64_encode($img);
} else {
return null;
}
}
示例5: function
Route::get('/contact', ['as' => 'contact_admin', 'uses' => 'ContactController@index']);
Route::post('/contact/update', ['as' => 'contact_admin_update', 'uses' => 'ContactController@update']);
Route::get('/sitemap', ['as' => 'sitemap_admin', 'uses' => 'SitemapController@index']);
Route::post('/sitemap/update', ['as' => 'sitemap_admin_update', 'uses' => 'SitemapController@update']);
});
// Images
// $type -> fit, crop, resize
Route::get('/assets/images/about/{width}/{height}/{name?}', ['as' => 'about_image', function ($width, $height, $name = 'cover', $type = 'fit') {
$img = Image::cache(function ($image) use($name, $width, $height, $type) {
$image->make(public_path('/assets/images/about/' . $name . '.jpg'))->{$type}($width, $height);
}, 5, true);
return $img->response('jpg');
}]);
Route::get('/assets/images/articles/{id}/{width}/{height}/{name?}', ['as' => 'article_image', function ($id, $width, $height, $name = 'cover', $type = 'fit') {
$img = Image::cache(function ($image) use($id, $name, $width, $height, $type) {
$image->make(public_path('/assets/images/articles/' . $id . '/' . $name . '.jpg'))->{$type}($width, $height);
}, 5, true);
return $img->response('jpg');
}]);
Route::get('/assets/images/projects/{id}/{width}/{height}/{name?}', ['as' => 'project_image', function ($id, $width, $height, $name = 'cover', $type = 'fit') {
$img = Image::cache(function ($image) use($id, $name, $width, $height, $type) {
$image->make(public_path('/assets/images/projects/' . $id . '/' . $name . '.jpg'))->{$type}($width, $height);
}, 5, true);
return $img->response('jpg');
}]);
Route::get('/assets/images/{name}/{width}/{height}', ['as' => 'cover_image', function ($name, $width, $height, $type = 'resize') {
$img = Image::cache(function ($image) use($name, $width, $height, $type) {
$image->make(public_path('/assets/images/' . $name . '/cover.jpg'))->{$type}($width, $height);
}, 5, true);
return $img->response('jpg');
}]);
示例6: function
Route::post('/chlang', 'BaseController@changeLanguage');
Route::post('/register', 'UserController@register');
Route::post('/login', 'UserController@doLogin');
Route::post('/logout', 'UserController@doLogout');
Route::post('/forgetpass', 'UserController@forget');
Route::get('/resetpassword/{code}', 'UserController@reset');
Route::post('/resetpassword', 'UserController@doReset');
Route::get('imgpost/{uid}/{src}', function ($uid, $src) {
$cacheImage = Image::cache(function ($image) use($uid, $src) {
$image->make(asset("/usr/{$uid}/" . $src))->fit(370, 370);
}, 10, false);
return Response::make($cacheImage, 200, array('Content-type' => 'image/jpeg'));
});
Route::get('imgpost/landscape/{uid}/{src}', function ($uid, $src) {
$cacheImage = Image::cache(function ($image) use($uid, $src) {
$image->make(asset("/usr/{$uid}/" . $src))->fit(600, 266);
}, 10, false);
return Response::make($cacheImage, 200, array('Content-type' => 'image/jpeg'));
});
Route::get('test', function () {
Mail::send('emails.message', array('desc' => 'test'), function ($message) {
$message->to('vendera.hadi@gmail.com', 'admin')->subject('Tifosiwar Alert');
});
});
Route::group(array('before' => 'auth'), function () {
Route::get('upload', 'PostController@upload');
Route::post('upload', 'PostController@postImage');
Route::post('ajaxupload', 'PostController@ajaxupload');
Route::get('myposts', 'PostController@myPosts');
Route::post('insertcomment', 'PostController@insertcomment');
Route::get('me', 'UserController@mypage');
示例7: function
<?php
/**
* Index Controller
*/
Route::get('/', 'IndexController@getHome');
Route::get('search', 'IndexController@getSearch');
Route::get('/vehicle/{id}', 'IndexController@getVehicle');
Route::post('/vehicle/{id}', 'IndexController@postVehicle');
Route::get('photo/{size}/{name}', function ($size = null, $name = null) {
if (!is_null($size) && !is_null($name)) {
$size = explode('x', $size);
$cacheImage = Image::cache(function ($image) use($size, $name) {
$img = $image->make(url('/uploads/photos/' . $name));
$img->fit($size[0], $size[1], function ($constraint) {
$constraint->aspectRatio();
});
$img->sharpen(10);
return $img;
}, 60, false);
return Response::make($cacheImage, 200, ['Content-Type' => 'image']);
} else {
abort(404);
}
});
/**
* Authentication
*/
Route::get('login', 'Auth\\AuthController@getLogin');
Route::post('login', 'Auth\\AuthController@postLogin');
Route::get('logout', 'Auth\\AuthController@getLogout');
/**
示例8: resize
public function resize($size)
{
$dotpos = stripos($size, '.');
if ($dotpos) {
$size = substr($size, 0, $dotpos);
}
$url = $this->relativeURL();
$w = null;
$h = null;
$s = null;
$raw = false;
$svg = false;
$retina = false;
if (File::exists($url) == false || empty($this->filename)) {
$file = AssetsController::missingImageResponse();
return (object) ['file' => $file, 'mime' => 'image/svg+xml', 'width' => $w, 'height' => $h, 'attr' => 'width="' . $w . '" height="' . $h . '"'];
}
if ($size != null) {
preg_match('/w(\\d+)/', $size, $wMatch);
preg_match('/h(\\d+)/', $size, $hMatch);
preg_match('/s(\\d+)/', $size, $sMatch);
preg_match('/@2x/', $size, $retinaMatch);
preg_match('/raw/', $size, $rawMatch);
preg_match('/svg/', $size, $svgMatch);
if ($retinaMatch) {
$retina = true;
}
if ($svgMatch) {
$svg = true;
}
if (count($wMatch) >= 2) {
$w = $wMatch[1];
}
if (count($hMatch) >= 2) {
$h = $hMatch[1];
}
if (count($sMatch) >= 2) {
$s = $sMatch[1];
}
if ($rawMatch) {
$raw = true;
}
}
// if we are svg just return the file
// todo: parse svg and alter width/height
if (File::extension($url) == 'svg') {
$svg = File::get($url);
if ($s != null) {
if ($retina) {
$s *= 2;
}
$svg = AssetsController::resizeSVG($svg, $s, null);
} else {
if ($w != null || $h != null) {
if ($retina) {
if ($w != null) {
$w *= 2;
}
if ($h != null) {
$h *= 2;
}
}
$svg = AssetsController::resizeSVG($svg, $w, $h);
}
}
if ($raw) {
$str = strpos($svg, "<svg") ? substr($svg, strpos($svg, "<svg")) : $svg;
return (object) ['file' => $str, 'mime' => 'image/svg+xml', 'width' => $w, 'height' => $h, 'attr' => 'width="' . $w . '" height="' . $h . '"'];
// return Response::make($str, 200, array('Content-Type' => 'image/svg+xml'));
}
return (object) ['file' => $svg, 'mime' => 'image/svg+xml', 'width' => $w, 'height' => $h, 'attr' => 'width="' . $w . '" height="' . $h . '"'];
// return Response::make($svg, 200, array('Content-Type' => 'image/svg+xml'));
}
$info = pathinfo($url);
$filename = $size ? $info['filename'] . '_' . $size . '.' . $info['extension'] : $info['filename'] . '.' . $info['extension'];
$path = $info['dirname'] . '/' . $filename;
if (File::exists($path)) {
$file = new \Symfony\Component\HttpFoundation\File\File($path);
$mime = $file->getMimeType();
$image_size = getimagesize($path);
return (object) ['path' => $path, 'file' => File::get($path), 'mime' => $mime, 'width' => $image_size[0], 'height' => $image_size[1], 'style' => 'width:' . $image_size[0] . 'px; height:' . $image_size[1] . 'px;', 'attr' => 'width="' . $image_size[0] . '" height="' . $image_size[1] . '"'];
}
$img = Image::cache(function ($image) use($url, $w, $h, $s, $path, $retina) {
$image->make($url);
if ($s != null) {
if ($retina) {
$s *= 2;
}
$image->fit($s, $s)->sharpen(3);
/*
$image->resize($desw, $desh, function ($constraint) {
$constraint->aspectRatio();
})->crop($s, $s);*/
} else {
if ($w != null || $h != null) {
if ($retina) {
if ($w != null) {
$w *= 2;
}
if ($h != null) {
//.........这里部分代码省略.........
示例9: array
$constraint->upsize();
});
}
});
return Response::make($cacheimage, 200, array('Content-Type' => 'image/jpeg'));
});
Route::get('imager/{pathkey}/{filename}/{w?}/{h?}', function ($pathkey, $filename, $w = 150, $h = 150) {
$cacheimage = Image::cache(function ($image) use($pathkey, $filename, $w, $h) {
switch ($pathkey) {
case 'useruploads':
$filepath = 'public/images/useruploads/' . $filename;
break;
case 'fullpath':
$filepath = 'images/useruploads/' . $filename;
break;
}
if ($h < 10000) {
return $image->make($filepath)->resize($w, $h);
} else {
return $image->make($filepath)->resize($w, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
});
return Response::make($cacheimage, 200, array('Content-Type' => 'image/jpeg'));
});
// Show one recipie
Route::get('/recipie/{id}', 'HomeController@showRecipie');
// show users profile
Route::get('/user/{id}', 'UserController@show');
Route::post('/user/{id}', 'UserController@update');
示例10: function
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::group(['middleware' => ['web']], function () {
//
});*/
Route::get('img/{model}/{template}/{name}', function ($model, $template, $name) {
return $cached_image = Image::cache(function ($image) use($model, $template, $name) {
switch ($template) {
case 'small':
return $image->make('uploads/' . $model . '/' . $name)->resize(80, 113);
break;
case 'medium':
return $image->make('uploads/' . $model . '/' . $name)->resize(160, 226);
break;
case 'large':
return $image->make('uploads/' . $model . '/' . $name)->resize(320, 452);
break;
case 'x_large':
return $image->make('uploads/' . $model . '/' . $name)->resize(470, 678);
break;
default:
return $image->make('uploads/' . $model . '/' . $name)->resize(160, 226);
}
//return $image->make('uploads/'.$model.'/'.$name)->filter(new \Intervention\Image\Templates\Small());
});
/* return Response::make($cached_image, 200, array(
'Content-Type'=> 'image/jpg'))->expire(\Carbon\Carbon::now()->addHour());*/
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/dashboard', 'Back\\DashboardController@index');
示例11: array
<?php
if (!empty($value)) {
?>
<hr class="no-margin-b"/>
<?php
}
?>
</div>
<?php
if (!empty($value)) {
?>
<div class="panel-body padding-sm">
<?php
echo HTML::anchor(PUBLIC_URL . $value, HTML::image(Image::cache($value, 100, 100, Image::HEIGHT)), array('class' => 'popup thumbnail pull-left no-margin-b', 'data-title' => __('View file')));
?>
<div class="checkbox-inline">
<label>
<?php
echo Form::checkbox($field->name . '_remove', 1, FALSE, array('class' => 'remove-file-checkbox'));
?>
<?php
echo __('Remove file');
?>
</label>
</div>
</div>
<?php
}
示例12: serveImage
/**
* Serve the File
* @param integer $width
* @param integer $height
* @param integer $quality Image Quality
* @param boolean $download If to download
* @return boolean
*/
public function serveImage($width, $height = null, $quality = null, $download = false, $image = null)
{
$folder = zbase_storage_path() . '/' . zbase_tag() . '/user/' . $this->id() . '/';
if (!empty($image)) {
$path = $folder . $image;
} else {
$path = $folder . $this->avatar;
}
if (!class_exists('\\Image')) {
$image = zbase_file_serve_image($path, $width, $height, $quality, $download);
if (!empty($image)) {
return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime']));
}
return zbase_abort(404);
}
// dd($this, $path, file_exists($path));
if (file_exists($path)) {
$cachedImage = \Image::cache(function ($image) use($width, $height, $path) {
if (empty($width)) {
$size = getimagesize($path);
$width = $size[0];
$height = $size[1];
}
if (!empty($width) && empty($height)) {
return $image->make($path)->resize($width, null, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
if (empty($width) && !empty($height)) {
return $image->make($path)->resize(null, $height, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
return $image->make($path)->resize($width, $height);
});
return \Response::make($cachedImage, 200, array('Content-Type' => 'image/png'));
}
return false;
}
示例13: function
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*
|--------------------------------------------------------------------------
| Image Routes
|--------------------------------------------------------------------------
| here is where all image's route located
|
*/
Route::get('image/{src}/{w?}/{h?}', function ($src, $w = 100, $h = 100) {
//intervention image caching
//closure and scoping anonymous function
$cacheimage = Image::cache(function ($image) use($src, $w, $h) {
return $image->make("admin/dist/img/" . $src)->resize($w, $h);
}, 2, true);
//dd($cachedimage);
return Response::make($cacheimage, 200, array('Content-Type' => 'image/png'));
});
/*
|--------------------------------------------------------------------------
| User Routes
|--------------------------------------------------------------------------
| here is where all user's route located
|
*/
Route::get('getDistrict', function () {
$prov_id = Input::get('prov_id');
$district = District::where('province_id', '=', $prov_id)->get();
return Response::json($district);
示例14: serveImage
/**
* Serve the File
* @param integer $width
* @param integer $height
* @param integer $quality Image Quality
* @param boolean $download If to download
* @return boolean
*/
public function serveImage($width, $height = null, $quality = null, $download = false)
{
$folder = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '_category' . '/' . $this->id() . '/';
$path = $folder . $this->avatar();
if (file_exists($path)) {
$cachedImage = \Image::cache(function ($image) use($width, $height, $path) {
if (empty($width)) {
$size = getimagesize($path);
$width = $size[0];
$height = $size[1];
}
if (!empty($width) && empty($height)) {
return $image->make($path)->resize($width, null, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
if (empty($width) && !empty($height)) {
return $image->make($path)->resize(null, $height, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
return $image->make($path)->resize($width, $height);
});
return \Response::make($cachedImage, 200, array('Content-Type' => $this->mimetype));
}
return false;
}
示例15: postFileResize
/**
* REsize the File
* @param type $file
* @param type $w
* @param type $h
* @param type $q
*/
public function postFileResize($path, $width, $height, $q = 80)
{
if (!class_exists('\\Image')) {
$image = zbase_file_serve_image($path, $width, $height, $q);
if (!empty($image)) {
header('Content-type: ' . $image['mime']);
return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime']));
}
return zbase_abort(404);
}
return \Image::cache(function ($image) use($width, $height, $path) {
if (empty($width)) {
$size = getimagesize($path);
$width = $size[0];
$height = $size[1];
}
if (!empty($width) && !empty($height)) {
return $image->make($path)->resize($width, $height, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
if (!empty($width) && empty($height)) {
return $image->make($path)->resize($width, null, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
if (empty($width) && !empty($height)) {
return $image->make($path)->resize(null, $height, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
});
}
return $image->make($path)->resize($width, $height);
});
}