Exemplo n.º 1
0
 /**
  * Create server instance.
  * @return Server The configured Glide server.
  */
 public function getServer()
 {
     $server = new Server($this->getSource(), $this->getCache(), $this->getApi());
     $server->setSourcePathPrefix($this->getSourcePathPrefix());
     $server->setCachePathPrefix($this->getCachePathPrefix());
     $server->setBaseUrl($this->getBaseUrl());
     return $server;
 }
Exemplo n.º 2
0
 /**
  * @param Request $request
  * @param string $path
  * @return StreamedResponse
  */
 public function show(Request $request, $path)
 {
     $params = $request->query();
     if ($this->secure) {
         $this->validateRequest($path, $params);
         $this->validateRequest($path, $params);
     }
     return $this->server->getImageResponse($path, $params);
 }
Exemplo n.º 3
0
 public function renderImageAction($image)
 {
     $width = $this->getWidth($image);
     $imageSource = str_replace('-' . $width, '', $image);
     $imagePath = $this->glide->makeImage($imageSource, ['w' => $width]);
     $imageBase = $this->glide->getCache()->read($imagePath);
     $this->glide->getCache()->put($image, $imageBase);
     $this->glide->outputImage($imageSource, ['w' => $width]);
 }
Exemplo n.º 4
0
 /**
  * Get configured server.
  * @return Server Configured Glide server.
  */
 public function getServer()
 {
     $server = new Server($this->getSource(), $this->getCache(), $this->getApi());
     $server->setSourcePathPrefix($this->getSourcePathPrefix());
     $server->setCachePathPrefix($this->getCachePathPrefix());
     $server->setGroupCacheInFolders($this->getGroupCacheInFolders());
     $server->setCacheWithFileExtensions($this->getCacheWithFileExtensions());
     $server->setDefaults($this->getDefaults());
     $server->setPresets($this->getPresets());
     $server->setBaseUrl($this->getBaseUrl());
     $server->setResponseFactory($this->getResponseFactory());
     return $server;
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->package('spatie/laravel-glide');
     $glideConfig = $this->app['config']->get('laravel-glide::config');
     $this->app['router']->get($glideConfig['baseURL'] . '/{all}', function () use($glideConfig) {
         $request = $this->app['request'];
         SignatureFactory::create($this->app['config']->get('app.key'))->validateRequest($request);
         // Set image source
         $source = new Filesystem(new Local($glideConfig['source']['path']));
         // Set image cache
         $cache = new Filesystem(new Local($glideConfig['cache']['path']));
         $this->writeIgnoreFile($glideConfig['cache']['path']);
         $api = GlideApiFactory::create();
         // Setup Glide server
         $server = new Server($source, $cache, $api);
         $server->setBaseUrl($glideConfig['baseURL']);
         echo $server->outputImage($request);
     })->where('all', '.*');
 }
Exemplo n.º 6
0
 /**
  * Get the cache path.
  * @param  mixed
  * @return string The cache path.
  */
 public function getCachePath()
 {
     $request = $this->resolveRequestObject(func_get_args());
     $requestPrefix = $this->makeRequestPrefix($request);
     $path = parent::getCachePath($request);
     if ($this->cachePathPrefix) {
         return str_replace($this->cachePathPrefix, $this->cachePathPrefix . '/' . $requestPrefix, $path);
     }
     return "{$requestPrefix}/{$path}";
 }
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $url = $request->getAttribute('virtualUri', '');
     if (!str_beginsWith($url, "{$this->settings->fileBaseUrl()}/")) {
         return $next();
     }
     // Strip prefix from URL
     $url = substr($url, strlen($this->settings->fileBaseUrl()) + 1);
     $path = "{$this->settings->fileArchivePath()}/{$url}";
     if (!file_exists($path)) {
         return $this->responseFactory->make(404, "Not found: {$path}", 'text/plain');
     }
     $mime = FileUtil::getMimeType($path);
     // Serve image file.
     if (FileUtil::isImageType($mime)) {
         // Use image manipulation parameters extracted from the request.
         return $this->glideServer->getImageResponse($url, $request->getQueryParams());
     }
     // Server non-image file.
     return $this->responseFactory->makeStream(fopen($path, 'rb'), 200, ['Content-Type' => $mime, 'Content-Length' => (string) filesize($path), 'Cache-Control' => 'max-age=31536000, public', 'Expires' => date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT']);
 }
Exemplo n.º 8
0
 /**
  * @return Server
  */
 public function getServer()
 {
     $server = new Server($this->getSource(), $this->getCache(), $this->getApi());
     if ($this->baseUrl !== null) {
         $server->setBaseUrl($this->baseUrl);
     }
     if ($this->sourcePathPrefix !== null) {
         $server->setSourcePathPrefix($this->sourcePathPrefix);
     }
     if ($this->cachePathPrefix !== null) {
         $server->setCachePathPrefix($this->cachePathPrefix);
     }
     return $server;
 }
Exemplo n.º 9
0
 public static function getPhoto(Server $server, Request $request, $id, $file)
 {
     $photo_file = $file;
     $path = "project/{$id}/photo/{$photo_file}";
     return $server->getImageResponse($path, $_GET);
 }
Exemplo n.º 10
0
 /**
  * Configure the Glide Server with the baseURL
  *
  * @param $source
  * @param $cache
  * @param $api
  *
  * @return Server
  */
 protected function setGlideServer($source, $cache, $api)
 {
     $server = new Server($source, $cache, $api);
     $server->setBaseUrl($this->glideConfig['baseURL']);
     return $server;
 }
Exemplo n.º 11
0
 public function doGenerateImageCache(Server $server, Request $request, $id)
 {
     $project = Project::find($id);
     $photos = $project->photos;
     foreach ($photos as $photo) {
         $server->makeImage("project/{$id}/photo/{$photo->filename}", ['w' => 300, 'h' => 300]);
     }
 }
Exemplo n.º 12
0
 /**
  * get the underlying filesystem that Glide is using
  * 
  * @return \League\Flysystem\FilesystemInterface $filesystem
  */
 private function filesystem()
 {
     return $this->server->getSource();
 }
Exemplo n.º 13
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bindIf('glide.source', function ($app) {
         $source = config('glide.source');
         if (is_callable($source)) {
             return $source();
         }
         return $source;
     }, true);
     $this->app->bindIf('glide.cache', function ($app) {
         $cache = config('glide.cache');
         if (is_callable($cache)) {
             return $cache();
         }
         return $cache;
     }, true);
     $this->app->bindIf('glide.manipulators', function ($app) {
         $manipulators = config('glide.manipulators');
         if (is_callable($manipulators)) {
             return $manipulators();
         }
         return $manipulators;
     }, true);
     $this->app->bindIf('glide.image_manager', function ($app) {
         $driver = config('glide.driver', 'gd');
         return new ImageManager(['driver' => $driver]);
     }, true);
     $this->app->bindIf('glide.api', function ($app) {
         $imageManager = $app['glide.image_manager'];
         $manipulators = $app['glide.manipulators'];
         return new Api($imageManager, $manipulators);
     }, true);
     $this->app->bindIf('glide.server', function ($app) {
         $source = $app['glide.source'];
         $cache = $app['glide.cache'];
         $api = $app['glide.api'];
         $server = new Server($source, $cache, $api);
         $request = $app['request'];
         $server->setResponseFactory(new LumenResponseFactory($request));
         return $server;
     }, true);
     $this->app->bindIf('glide.signature', function ($app) {
         $app->configure('app');
         $key = config('app.key');
         return SignatureFactory::create($key);
     });
     $this->app->bindIf('glide.image_controller', function ($app) {
         $server = $app['glide.server'];
         $signature = $app['glide.signature'];
         $secure = config('glide.secure', true);
         $prefix = config('glide.uri');
         return new ImageController($server, $signature, $secure, $prefix);
     });
     $this->app->bindIf('glide.url_builder', function ($app) {
         $baseUrl = $app['request']->root() . '/' . config('glide.uri') . '/';
         $secure = config('glide.secure', true);
         $signature = null;
         if ($secure) {
             $signature = $app['glide.signature'];
         }
         return new UrlBuilder($baseUrl, $signature);
     });
     $this->app->alias('glide.image_manager', ImageManager::class);
     $this->app->alias('glide.api', Api::class);
     $this->app->alias('glide.server', Server::class);
     $this->app->alias('glide.signature', Signature::class);
     $this->app->alias('glide.image_controller', ImageController::class);
     $this->app->alias('glide.url_builder', UrlBuilder::class);
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     return $this->server->getImageResponse($request);
 }
Exemplo n.º 15
0
 public static function getPhoto(Server $server, Request $request, $id, $file)
 {
     $photo_file = $file;
     $path = "post/{$id}/photo/{$photo_file}";
     return $server->outputImage($path, $_GET);
 }
Exemplo n.º 16
0
 public function image(Server $server, Request $request)
 {
     $server->outputImage($request);
 }
Exemplo n.º 17
0
 public function getFile(Server $server, Request $request, $path)
 {
     $server->outputImage($path, $request->all());
 }
Exemplo n.º 18
0
 public function show(GlideServer $server, Request $request)
 {
     return $server->outputImage(strtok($request->server->get('REQUEST_URI'), '?'), $request->all());
 }