当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::encode方法代码示例

本文整理汇总了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());
     }
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:30,代码来源:InterventionRequest.php

示例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;
 }
开发者ID:dsentker,项目名称:AvatarMaker,代码行数:10,代码来源:AvatarMaker.php

示例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;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:14,代码来源:StreamCommand.php

示例4: save

 /**
  * @param Image  $image
  * @param string $path
  *
  * @return bool
  */
 public function save(Image $image, $path)
 {
     return $this->flysystem->put($path, $image->encode());
 }
开发者ID:fraterblack,项目名称:attacher,代码行数:10,代码来源:Fly.php

示例5: 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);
 }
开发者ID:bravo3,项目名称:image-manager,代码行数:21,代码来源:InterventionEncoder.php

示例6: 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.");
     }
 }
开发者ID:bigwhoop,项目名称:trumpet,代码行数:28,代码来源:ImageCommand.php

示例7: store

 /**
  * Store preview in storage.
  *
  * @param \Intervention\Image\Image $image
  * @param string                    $path
  */
 private function store($image, $path)
 {
     Storage::put($path, $image->encode('jpg'));
 }
开发者ID:ntzm,项目名称:laravit,代码行数:10,代码来源:GeneratePreview.php

示例8: 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);
 }
开发者ID:jorzhikgit,项目名称:MLM-Nexus,代码行数:12,代码来源:_ide_helper.php

示例9: 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));
 }
开发者ID:williamoliveira,项目名称:attachable,代码行数:9,代码来源:InterventionImageProcessor.php

示例10: 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));
 }
开发者ID:microstudi,项目名称:silex-image-controller,代码行数:9,代码来源:ImageController.php

示例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;
 }
开发者ID:CbCaio,项目名称:Image-Attacher,代码行数:10,代码来源:FileManager.php

示例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')));
 }
开发者ID:awebc,项目名称:web_xbf,代码行数:10,代码来源:Output.php

示例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);
 }
开发者ID:igaster,项目名称:laravel-image-versions,代码行数:11,代码来源:AbstractTransformation.php

示例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;
 }
开发者ID:EdgarPost,项目名称:image,代码行数:11,代码来源:ChecksumCommand.php

示例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;
 }
开发者ID:devhook,项目名称:devhook,代码行数:80,代码来源:ImageController.php


注:本文中的Intervention\Image\Image::encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。