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); } }
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); }
/** * 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)); } }
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; } }
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'); }]);
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('*****@*****.**', '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');
<?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'); /**
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) { $h *= 2; } } $image->resize($w, $h, function ($constraint) { $constraint->aspectRatio(); }); } } $image->save($path); return $image; }); $file = new \Symfony\Component\HttpFoundation\File\File($url); $mime = $file->getMimeType(); return (object) ['path' => $path, 'file' => $file, 'mime' => $mime]; }
$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');
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');
<?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 }
/** * 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; }
| 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);
/** * 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; }
/** * 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); }); }
| | Here is where you can register all of the routes for an application. | 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. | */ Route::group(['middleware' => ['web']], function () { Route::get('/', 'TestController@index'); // Route::get('/', function () { // return view('welcome')->with('Developer', 'Amir Hossenzadeh'); // }); Route::get('/photo/{size}/{name}', function ($size = null, $name = null) { if (!is_null($size) && !is_null($name)) { $size = explode('x', $size); $cache_image = Image::cache(function ($image) use($size, $name) { return $image->make(url('/photos/' . $name))->resize($size[0], $size[1]); }, env('CACHE_PHOTO_MINUTE')); // cache for 10 minutes return Response::make($cache_image, 200, ['Content-Type' => 'image']); } else { abort(404); } }); Route::get('language/{lang}', function ($lang = 'en') { session()->put('locale', $lang); return back(); }); /*Route::group(array('prefix'=>'checkout'),function(){ dd('Route'); });*/ });
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::get('/error-404', ['as' => 'error_404', 'uses' => 'HomeController@error404']); Route::get('/error-503', ['as' => 'error_503', 'uses' => 'HomeController@error503']); Route::get('/image/{year}/{src}/{h?}', ['as' => 'imagen', function ($year, $src, $h = 75) { $cacheimage = Image::cache(function ($image) use($year, $src, $h) { return $image->make(asset('images/assets/' . $year . '/' . $src))->resize(null, $h, function ($constraint) { $constraint->aspectRatio(); }); }, true); return Response::make($cacheimage, 200, ['Content-type' => 'image/jpeg']); }]); Route::get('/', ['as' => 'home', 'uses' => 'HomeController@index']); // Noticias Route::get('/noticias', ['as' => 'noticias', 'uses' => 'NoticiaController@index']); Route::get('/noticia/{slug}/{id}', ['as' => 'noticia', 'uses' => 'NoticiaController@show']); // Eventos Route::get('/eventos', ['as' => 'activities', 'uses' => 'ActivityController@index']); Route::get('/evento/{slug}/{id}', ['as' => 'activity', 'uses' => 'ActivityController@show']); // Carreras Route::get('/carreras', ['as' => 'courses', 'uses' => 'CourseController@index']); Route::get('/carrera/{slug}/{id}', ['as' => 'course', 'uses' => 'CourseController@show']); // Galerias
}); Route::resource('user', 'UserController', ['except' => ['show']]); }); }); // 认证路由... Route::get('auth/login', 'Auth\\AuthController@getLogin'); Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::get('auth/logout', 'Auth\\AuthController@getLogout'); }); //上传路由... Route::post('upload', ['as' => 'upload', 'uses' => 'UploadController@store']); // 图片处理包测试路由 Route::get('image', function () { // 打开图片make(),参数是图片路径,调整大小resize(),参数是目标尺寸,回调函数是等比约束,填充颜色fill(),参数是rgba的数组,更多参见文档 $img = Image::make('./uploads/image/2016_03_17/20160317_040349_32527.jpg')->resize(null, 1000, function ($constraint) { $constraint->aspectRatio(); //是否等比 $constraint->upsize(); //最大尺寸限制,防止过于放大,图片失真 })->fill(array(0, 0, 9, 0.5))->save('./uploads/image/2016_03_17/new.jpg'); //保存新图片 // $img->crop(100, 100, 50, 50); //裁剪图片 // 添加水印图片 $img->insert('./uploads/image/2016_03_17/20160317_040349_94696.jpg', 'bottom-right', 10, 10)->save('./uploads/image/2016_03_17/water.jpg'); //添加水印图片 // create a cached image and set a lifetime and return as object instead of string $img = Image::cache(function ($image) { $image->make('./uploads/image/2016_03_17/water.jpg')->resize(300, 200)->greyscale(); }, 10, true)->save('./uploads/image/2016_03_17/cache.jpg'); return $img->response('jpg'); });
if (!empty($files)) { ?> <div class="panel-body padding-sm no-padding-hr clearfix"> <?php foreach ($files as $id => $file) { ?> <div class="thumbnail pull-left margin-xs-hr"> <a href="<?php echo PUBLIC_URL . $file; ?> " rel="<?php echo $field->name; ?> " class="popup" data-title="false"> <?php echo HTML::image(Image::cache($file, 100, 100, Image::HEIGHT, TRUE)); ?> </a> <label class="checkbox-inline"><?php echo Form::checkbox($field->name . '_remove[]', $id) . ' ' . __('Remove'); ?> </label> </div> <?php } ?> </div> <?php } ?> </div>