Skip to content

Instantly share code, notes, and snippets.

@wayneashleyberry
Created December 7, 2015 12:35
Show Gist options
  • Save wayneashleyberry/96303260eda18f73b85b to your computer and use it in GitHub Desktop.
Save wayneashleyberry/96303260eda18f73b85b to your computer and use it in GitHub Desktop.
Glide
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use League\Glide\Responses\SymfonyResponseFactory;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Glide\ServerFactory;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class ImageController extends Controller
{
public function show(Request $request, $path)
{
$client = S3Client::factory([
'credentials' => [
'key' => env('S3_KEY'),
'secret' => env('S3_SECRET'),
],
'region' => env('S3_REGION'),
'version' => env('S3_VERSION')
]);
$source = new AwsS3Adapter($client, env('S3_BUCKET'));
$cache = new AwsS3Adapter($client, env('S3_BUCKET'), 'www');
$server = ServerFactory::create([
'base_url' => '/img/',
'source' => new Filesystem($source),
'cache' => new Filesystem($cache),
'response' => new SymfonyResponseFactory,
'defaults' => [
'q' => 80,
]
]);
return $server->getImageResponse($request->path(), $request->input());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment