/** * Apply resize * * @param string $path * @return Psr-7 stream */ public function apply($path) { $library = $this->libraryRepostiory->findByPath($path)->toArray(); $storage = $library['description']['is_moved'] ? $library['description']['storage'] : 'local'; $filesystem = $this->filesystemFactory->disk($storage); $stream = $filesystem->getDriver()->readStream($path); $lastModified = $filesystem->lastModified($path); return $this->imageManager->cache(function ($image) use($stream, $lastModified) { $this->process($image->setProperty('lastModified', $lastModified)->make($stream)); }, $this->getLifetime()); }
public function view($width = null, $height = null) { $filename = $this->asset->exists() ? $this->asset->getFilename() : __DIR__ . '/../../../../vendor/boomcms/boom-core/img/placeholder.png'; if ($width || $height) { $image = $this->manager->cache(function ($manager) use($width, $height, $filename) { return $manager->make($filename)->resize($width != 0 ? $width : null, $height != 0 ? $height : null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode($this->encoding); }); } else { $image = $this->manager->make($this->asset->getFilename())->encode(); } return $this->response->header('content-type', $this->asset->getMimetype())->setContent($image); }
/** * @param MediaRepositoryInterface $media * @param ImageManager $images * @param Filesystem $files * @return bool * @throws Exception */ public function handle(MediaRepositoryInterface $media, ImageManager $images, Filesystem $files) { list($width, $height) = $this->dimensions($this->size); $path = $this->getPath($files); $constraint = $this->constraint($width, $height); $image = $images->cache(function ($image) use($width, $height, $constraint) { if ($this->cachedPath) { $image = $image->make($this->cachedPath); } else { $image = $image->make(public_path($this->image->path)); } $image->resize($width, $height, $constraint); }, 60, true)->save($path); if ($image) { //always fetch the actual width and height from the image, //one of them could have been null to auto scale the image. $width = $image->getWidth(); $height = $image->getHeight(); //use html public path to store in database $path = $this->getPath($files, true); try { $media->createThumbnailImage($this->getPayload($width, $height, $path), $this->image); } catch (Exception $e) { $files->delete(public_path($path)); unset($image); return false; } unset($image); } }
public function view($width = null, $height = null) { if (!empty($width) || !empty($height)) { $image = $this->manager->cache(function (ImageCache $cache) use($width, $height) { $width = empty($width) ? null : $width; $height = empty($height) ? null : $height; return $cache->make($this->asset->getFilename())->resize($width, $height, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode($this->encoding); }); } else { $image = $this->manager->make($this->asset->getFilename())->encode(); } return $this->response->header('content-type', $this->asset->getMimetype())->setContent($image); }
public function thumb($width = null, $height = null) { $manager = new ImageManager(); $thumb = new PdfThumbnail($this->asset); if ($width && $height) { $image = $manager->cache(function ($manager) use($width, $height, $thumb) { return $manager->make($thumb->getAndMakeFilename())->fit($width, $height); }); } else { $image = $manager->make($thumb->getAndMakeFilename())->encode(); } return $this->response->header('content-type', 'image/png')->setContent($image); }
/** * Get HTTP response of template applied image file * * @param string $template * @param string $filename * @return Illuminate\Http\Response */ public function getImage($template, $filename) { $template = $this->getTemplate($template); $path = $this->getImagePath($filename); // image manipulation based on callback $manager = new ImageManager(Config::get('image')); $content = $manager->cache(function ($image) use($template, $path) { if ($template instanceof Closure) { // build from closure callback template $template($image->make($path)); } else { // build from filter template $image->make($path)->filter($template); } }, config('imagecache.lifetime')); return $this->buildResponse($content); }
public function thumb($width = null, $height = null) { if (!$this->asset->hasThumbnail()) { return parent::thumb(); } $thumbnail = $this->asset->getThumbnail(); $filename = $thumbnail->getFilename(); $im = new ImageManager(); if ($width && $height) { $image = $im->cache(function ($manager) use($width, $height, $filename) { return $manager->make($filename)->fit($width, $height); }); } else { $image = $im->make($filename)->encode(); } return $this->response->header('content-type', $thumbnail->getMimetype())->setContent($image); }
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); }
/** * Create new cached image and run callback * (requires additional package intervention/imagecache) * * @param \Closure $callback * @param integer $lifetime * @param boolean $returnObj * @return \Intervention\Image\Image * @static */ public static function cache($callback, $lifetime = null, $returnObj = false) { return \Intervention\Image\ImageManager::cache($callback, $lifetime, $returnObj); }