/** * @param AssetInterface $asset */ public function __construct(AssetInterface $asset) { $this->asset = $asset; if ($this->asset->getExtension() !== 'pdf') { throw new InvalidArgumentException('Given asset is not a PDF'); } }
public function thumb($width = null, $height = null) { if (!$this->asset->hasThumbnail()) { return $this->response->header('Content-type', 'image/png')->setContent(readfile(__DIR__ . "/../../../../../public/img/extensions/{$this->asset->getExtension()}.png")); } $thumbnail = $this->asset->getThumbnail(); $filename = $thumbnail->getFilename(); $im = new ImageManager(); if ($width || $height) { $image = $im->cache(function (ImageCache $cache) use($width, $height, $filename) { $width = empty($width) ? null : $width; $height = empty($height) ? null : $height; return $cache->make($filename)->resize($width, $height, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode('image/png'); }); } else { $image = $im->make($filename)->encode(); } return $this->response->header('content-type', $thumbnail->getMimetype())->setContent($image); }
public function thumb($width = null, $height = null) { return $this->response->header('Content-type', 'image/png')->setContent(readfile(__DIR__ . "/../../../../../public/img/extensions/{$this->asset->getExtension()}.png")); }