Exemplo n.º 1
0
 /**
  * Returns instance of ImageInfo about fetched thumbnail
  *
  * @param string $name
  * @return \Imager\ImageInfo
  */
 public function fetchThumbnail($name)
 {
     if (!isset($name) || Strings::length($name) === 0) {
         throw new InvalidArgumentException('Name of fetched file cannot be empty.');
     }
     $thumbnail = $this->getThumbnailPath($name);
     if (!file_exists($thumbnail)) {
         $msg = sprintf('Thumbnail image "%s" not exists.', $thumbnail);
         throw new NotExistsException($msg);
     }
     $parts = Helpers::parseName($name);
     if (isset($parts['id'])) {
         $source = $this->fetch($parts['id']);
     }
     return new ImageInfo($thumbnail, $source);
 }
Exemplo n.º 2
0
 public function match(Http\IRequest $request)
 {
     $url = $request->getUrl();
     if (Strings::contains($url->path, $this->basePath) === false) {
         return;
     }
     $imgUrl = Strings::after($url->path, $this->basePath);
     $imgUrl = Strings::after($imgUrl, '/', -1);
     $parts = Imager\Helpers::parseName($imgUrl);
     if (!isset($parts['id'])) {
         return;
     }
     $url->setQueryParameter('id', $parts['id'])->setQueryParameter('width', $parts['width'])->setQueryParameter('height', $parts['height'])->setQueryParameter('quality', $parts['quality']);
     $response = new ImageResponse($this->repository, $this->imageFactory);
     $response->send(new Http\Request($url), new Http\Response());
 }