本文整理汇总了PHP中Intervention\Image\ImageManager::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageManager::cache方法的具体用法?PHP ImageManager::cache怎么用?PHP ImageManager::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\ImageManager
的用法示例。
在下文中一共展示了ImageManager::cache方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* 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());
}
示例2: view
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);
}
示例3: handle
/**
* @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);
}
}
示例4: view
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);
}
示例5: thumb
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);
}
示例6: getImage
/**
* 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);
}
示例7: thumb
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);
}
示例8: thumb
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);
}
示例9: cache
/**
* 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);
}