本文整理汇总了PHP中Intervention\Image\Image::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::encode方法的具体用法?PHP Image::encode怎么用?PHP Image::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle request to convert it to a Response object.
*/
public function handle()
{
try {
if (!$this->request->query->has('image')) {
throw new FileNotFoundException("No valid image path found in URI", 1);
}
$nativePath = $this->configuration->getImagesPath() . '/' . $this->request->query->get('image');
$this->nativeImage = new File($nativePath);
$this->parseQuality();
if ($this->configuration->hasCaching()) {
$cache = new FileCache($this->request, $this->nativeImage, $this->configuration->getCachePath(), $this->logger, $this->quality, $this->configuration->getTtl(), $this->configuration->getGcProbability(), $this->configuration->getUseFileChecksum());
$cache->setDispatcher($this->dispatcher);
/** @var Response response */
$this->response = $cache->getResponse(function (InterventionRequest $interventionRequest) {
return $interventionRequest->processImage();
}, $this);
} else {
$this->processImage();
$this->response = new Response((string) $this->image->encode(null, $this->quality), Response::HTTP_OK, ['Content-Type' => $this->image->mime(), 'Content-Disposition' => 'filename="' . $this->nativeImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
$this->response->setLastModified(new \DateTime('now'));
}
} catch (FileNotFoundException $e) {
$this->response = $this->getNotFoundResponse($e->getMessage());
} catch (\RuntimeException $e) {
$this->response = $this->getBadRequestResponse($e->getMessage());
}
}
示例2: toBase64
/**
* @return string
*/
public function toBase64()
{
if (!$this->image) {
throw new \LogicException(sprintf('You must call %s::makeAvatar() first!', __CLASS__));
}
return $this->image->encode('data-url', 100)->encoded;
}
示例3: execute
/**
* Builds PSR7 stream based on image data. Method uses Guzzle PSR7
* implementation as easiest choice.
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$format = $this->argument(0)->value();
$quality = $this->argument(1)->between(0, 100)->value();
$this->setOutput(\GuzzleHttp\Psr7\stream_for($image->encode($format, $quality)->getEncoded()));
return true;
}
示例4: createVariation
/**
* {@inheritdoc}
*/
public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null)
{
try {
$img = new InterventionImage($this->data);
} catch (\Intervention\Image\Exception\InvalidImageDataStringException $e) {
throw new BadImageException('Bad image data', 0, $e);
} catch (\Intervention\Image\Exception\ImageNotFoundException $e) {
throw new BadImageException('Not an image', 0, $e);
}
if ($dimensions) {
if ($dimensions->getGrab()) {
$img->grab($dimensions->getWidth(), $dimensions->getHeight());
} else {
$img->resize($dimensions->getWidth(), $dimensions->getHeight(), $dimensions->getMaintainRatio(), $dimensions->canUpscale());
}
}
return $img->encode($output_format->key(), $quality);
}
示例5: returnImage
/**
* @param Image $img
* @param CommandParams $params
*
* @return string
*
* @throws ExecutionFailedException
*/
private function returnImage(Image $img, CommandParams $params)
{
switch ($this->returnType) {
case self::RETURN_TYPE_URL:
case self::RETURN_TYPE_PATH:
$tmpDir = $this->executionContext->ensureTempDirectory();
$tmpFile = $tmpDir . '/' . md5($params->getParams()) . '.png';
$img->encode('png')->save($tmpFile);
if ($this->returnType === self::RETURN_TYPE_PATH) {
return $tmpFile;
}
return '<img src="/_tmp/' . basename($tmpFile) . '">';
case self::RETURN_TYPE_DATA_URL:
return '![Image](' . $img->encode('data-url')->getEncoded() . ')';
case self::RETURN_TYPE_DATA:
return $img->encode('png')->getEncoded();
default:
throw new ExecutionFailedException("Invalid return type '{$this->returnType}' detected.");
}
}
示例6: store
/**
* Store preview in storage.
*
* @param \Intervention\Image\Image $image
* @param string $path
*/
private function store($image, $path)
{
Storage::put($path, $image->encode('jpg'));
}
示例7: encode
/**
* Encode image in different formats
*
* @param string $format
* @param integer $quality
* @return string
* @static
*/
public static function encode($format = null, $quality = 90)
{
return \Intervention\Image\Image::encode($format, $quality);
}
示例8: saveSingleTemplate
/**
* @param AttachableModel $model
* @param Image $image
* @param $templateName
*/
protected function saveSingleTemplate(AttachableModel $model, Image $image, $templateName)
{
$this->storage->put($model->getPath($templateName), $image->encode($model->file_extension));
}
示例9: streamImage
private function streamImage(Application $app, Image $image)
{
$image->encode(null, $this->default_quality);
$mime = self::getMimeFromData($image->getEncoded());
return $app->stream(function () use($image) {
// echo $image->response();
echo $image->getEncoded();
}, 200, array('Content-Type' => $mime));
}
示例10: save
/**
* @param Image $image
* @param string $path
*
* @return bool
*/
public function save(Image $image, $path)
{
return $this->flysystem->put($path, $image->encode());
}
示例11: update
/**
* @param Image $image
* @param string $path
* @param string $oldPath
* @return bool
*/
public function update(Image $image, $path, $oldPath)
{
return $this->delete($oldPath) ? $this->flysystem->put($path, $image->encode()) : FALSE;
}
示例12: run
/**
* Perform output image manipulation.
* @param Request $request The request object.
* @param Image $image The source image.
* @return Image The manipulated image.
*/
public function run(Request $request, Image $image)
{
return $image->encode($this->getFormat($image, $request->get('fm')), $this->getQuality($request->get('q')));
}
示例13: onSaving
/**
* This callback is executed before the image is saved. You can override this
* if you want to prepere the image for saving (eg set file format etc).
*
* @param \Intervention\Image\Image $image
* @return null
*/
public function onSaving(Image $image)
{
$image->encode('jpg', 75);
}
示例14: execute
/**
* Calculates checksum of given image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$this->setOutput(md5($image->encode('png')));
return true;
}
示例15: missingMethod
public function missingMethod($args)
{
if (count($args) < 3) {
return parent::missingMethod($args);
}
if ($args[0] == 'force') {
array_shift($args);
}
$modelKeyword = $args[0];
$modelClass = \Devhook::getClassByKey($modelKeyword);
$id = $args[1];
$file = $args[2];
$parts = explode('-', $file);
if (count($parts) == 3) {
list($field, $sizeKey, $file) = $parts;
@(list($imageId, $ext) = explode('.', $file));
} else {
$imageId = false;
@(list($field, $file) = $parts);
@(list($sizeKey, $ext) = explode('.', $file));
}
if (!$field || !$sizeKey || $ext != 'jpg') {
return parent::missingMethod($args);
}
$model = $modelClass::find($id);
if (!$model || !$model->{$field}) {
return parent::missingMethod($args);
}
// $fileExt = pathinfo($model->$field, PATHINFO_EXTENSION);
$fields = (array) $model->getFields();
$modelField = isset($fields[$field]) ? $fields[$field] : false;
if (!$modelField || empty($modelField->type)) {
return parent::missingMethod($args);
}
$imageTypes = array('image');
$type = $modelField->type;
$sizes = (array) $modelField->settings('sizes');
$imageAdminThumb = Config::get('devhook.imageAdminThumb');
if (!in_array($type, $imageTypes) || empty($sizes[$sizeKey])) {
return parent::missingMethod($args);
}
$watermark = $modelField->settings('watermark');
$size = $sizes[$sizeKey];
$width = $size[0];
$hegiht = $size[1];
$crop = isset($size[2]) ? $size[2] : false;
$quality = isset($size[3]) ? $size[3] : 95;
if ($imageId) {
$imageFile = \Image::where('imageable_type', $modelKeyword)->where('imageable_id', $id)->find($imageId);
if (!$imageFile) {
return parent::missingMethod($args);
}
$imageFile = $imageFile->path;
} else {
$imageFile = $model->{$field};
}
ini_set('memory_limit', '200M');
$image = new IMG(public_path($imageFile));
if ($crop) {
$image->grab($width, $hegiht);
} else {
$image->resize($width, $hegiht, true);
}
if ($watermark) {
if (!$watermark['sizes'] || in_array($sizeKey, $watermark['sizes'])) {
$image->insert($watermark['image'], $watermark['offset'][0], $watermark['offset'][1], $watermark['position']);
}
}
$tmpFile = public_path($model->{$field}) . '.tmp_' . uniqid();
$newFile = public_path(Config::get('devhook.imageRoute') . '/' . implode('/', $args));
$newPath = dirname($newFile);
if (!File::exists($newPath)) {
File::makeDirectory($newPath, 0777, true);
}
$image->save($newFile, $quality);
$img = $image->encode($ext, $quality);
$response = Response::make($img, 200);
$response->header('Content-Type', 'image/jpeg');
return $response;
}