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


PHP ImagineInterface::load方法代码示例

本文整理汇总了PHP中Imagine\Image\ImagineInterface::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ImagineInterface::load方法的具体用法?PHP ImagineInterface::load怎么用?PHP ImagineInterface::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Imagine\Image\ImagineInterface的用法示例。


在下文中一共展示了ImagineInterface::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getImage

 /**
  * {@inheritDoc}
  */
 public function getImage($relativePath, $filter)
 {
     $eventManager = $this->getEventManager();
     $eventManager->trigger(__FUNCTION__, $this, ['relativePath' => $relativePath, 'filter' => $filter]);
     $filterOptions = $this->filterManager->getFilterOptions($filter);
     $binary = $this->loaderManager->loadBinary($relativePath, $filter);
     if (isset($filterOptions['format'])) {
         $format = $filterOptions['format'];
     } else {
         $format = $binary->getFormat() ?: 'png';
     }
     $imageOutputOptions = [];
     if (isset($filterOptions['quality'])) {
         $imageOutputOptions['quality'] = $filterOptions['quality'];
     }
     if ($format === 'gif' && $filterOptions['animated']) {
         $imageOutputOptions['animated'] = $filterOptions['animated'];
     }
     if ($this->cacheManager->isCachingEnabled($filter, $filterOptions) && $this->cacheManager->cacheExists($relativePath, $filter, $format)) {
         $imagePath = $this->cacheManager->getCachePath($relativePath, $filter, $format);
         $filteredImage = $this->imagine->open($imagePath);
     } else {
         $image = $this->imagine->load($binary->getContent());
         $filteredImage = $this->filterManager->getFilter($filter)->apply($image);
         if ($this->cacheManager->isCachingEnabled($filter, $filterOptions)) {
             $this->cacheManager->createCache($relativePath, $filter, $filteredImage, $format, $imageOutputOptions);
         }
     }
     $args = ['relativePath' => $relativePath, 'filter' => $filter, 'filteredImage' => $filteredImage, 'format' => $format];
     $eventManager->trigger(__FUNCTION__ . '.post', $this, $args);
     return ['image' => $filteredImage, 'format' => $format, 'imageOutputOptions' => $imageOutputOptions];
 }
开发者ID:shitikovkirill,项目名称:zend-shop.com,代码行数:35,代码来源:ImageService.php

示例2: showAction

 /**
  * @param Request $request
  * @param string  $filename
  *
  * @throws NotFoundHttpException If media is not found
  *
  * @return Response
  */
 public function showAction(Request $request, $filename)
 {
     if (!$this->filesystem->has($filename)) {
         throw new NotFoundHttpException(sprintf('Media "%s" not found', $filename));
     }
     $response = new Response($content = $this->filesystem->read($filename));
     $mime = $this->filesystem->mimeType($filename);
     if (($filter = $request->query->get('filter')) && null !== $mime && 0 === strpos($mime, 'image')) {
         try {
             $cachePath = $this->cacheManager->resolve($request, $filename, $filter);
             if ($cachePath instanceof Response) {
                 $response = $cachePath;
             } else {
                 $image = $this->imagine->load($content);
                 $response = $this->filterManager->get($request, $filter, $image, $filename);
                 $response = $this->cacheManager->store($response, $cachePath, $filter);
             }
         } catch (\RuntimeException $e) {
             if (0 === strpos($e->getMessage(), 'Filter not defined')) {
                 throw new HttpException(404, sprintf('The filter "%s" cannot be found', $filter), $e);
             }
             throw $e;
         }
     }
     if ($mime) {
         $response->headers->set('Content-Type', $mime);
     }
     return $response;
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:37,代码来源:MediaController.php

示例3: apply

 /**
  * @param BinaryInterface $binary
  * @param array           $config
  *
  * @throws \InvalidArgumentException
  *
  * @return Binary
  */
 public function apply(BinaryInterface $binary, array $config)
 {
     $config = array_replace(array('filters' => array(), 'quality' => 100, 'animated' => false), $config);
     $image = $this->imagine->load($binary->getContent());
     foreach ($config['filters'] as $eachFilter => $eachOptions) {
         if (!isset($this->loaders[$eachFilter])) {
             throw new \InvalidArgumentException(sprintf('Could not find filter loader for "%s" filter type', $eachFilter));
         }
         $image = $this->loaders[$eachFilter]->load($image, $eachOptions);
     }
     $options = array('quality' => $config['quality']);
     if (isset($config['jpeg_quality'])) {
         $options['jpeg_quality'] = $config['jpeg_quality'];
     }
     if (isset($config['png_compression_level'])) {
         $options['png_compression_level'] = $config['png_compression_level'];
     }
     if (isset($config['png_compression_filter'])) {
         $options['png_compression_filter'] = $config['png_compression_filter'];
     }
     if ($binary->getFormat() === 'gif' && $config['animated']) {
         $options['animated'] = $config['animated'];
     }
     $filteredFormat = isset($config['format']) ? $config['format'] : $binary->getFormat();
     $filteredContent = $image->get($filteredFormat, $options);
     $filteredMimeType = $filteredFormat === $binary->getFormat() ? $binary->getMimeType() : $this->mimeTypeGuesser->guess($filteredContent);
     return $this->applyPostProcessors(new Binary($filteredContent, $filteredMimeType, $filteredFormat), $config);
 }
开发者ID:Tecnocreaciones,项目名称:ImagineService,代码行数:36,代码来源:FilterManager.php

示例4: find

 /**
  * {@inheritDoc}
  */
 public function find($id)
 {
     $image = $this->dm->getRepository($this->class)->findAll()->getCollection()->findOne(array("_id" => new \MongoId($id)));
     if (!$image) {
         throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $id));
     }
     return $this->imagine->load($image['file']->getBytes());
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:11,代码来源:GridFSLoader.php

示例5: resize

 /**
  * {@inheritdoc}
  */
 public function resize(MediaInterface $media, File $in, File $out, $format, array $settings)
 {
     if (!isset($settings['width'])) {
         throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderName()));
     }
     $image = $this->adapter->load($in->getContent());
     $content = $image->thumbnail($this->getBox($media, $settings), $this->mode)->get($format, array('quality' => $settings['quality']));
     $out->setContent($content, $this->metadata->get($media, $out->getName()));
 }
开发者ID:nicolasricci,项目名称:SonataMediaBundle,代码行数:12,代码来源:SimpleResizer.php

示例6: convert

 /**
  * {@inheritdoc}
  */
 public function convert(FileVersion $fileVersion, $formatKey)
 {
     $content = $this->storage->loadAsString($fileVersion->getName(), $fileVersion->getVersion(), $fileVersion->getStorageOptions());
     $extractedImage = $this->mediaImageExtractor->extract($content);
     try {
         $image = $this->imagine->load($extractedImage);
     } catch (RuntimeException $e) {
         throw new InvalidFileTypeException($e->getMessage());
     }
     $image = $this->toRGB($image);
     $format = $this->getFormat($formatKey);
     $cropParameters = $this->getCropParameters($image, $fileVersion->getFormatOptions()->get($formatKey), $this->formats[$formatKey]);
     if (isset($cropParameters)) {
         $image = $this->applyFormatCrop($image, $cropParameters);
     }
     if (isset($format['scale']) && $format['scale']['mode'] !== ImageInterface::THUMBNAIL_INSET) {
         $image = $this->applyFocus($image, $fileVersion, $format['scale']);
     }
     if (isset($format['scale'])) {
         $image = $this->applyScale($image, $format['scale']);
     }
     if (isset($format['transformations'])) {
         $image = $this->applyTransformations($image, $format['transformations']);
     }
     $image->strip();
     // Set Interlacing to plane for smaller image size.
     if (count($image->layers()) == 1) {
         $image->interlace(ImageInterface::INTERLACE_PLANE);
     }
     $imagineOptions = $format['options'];
     $imageExtension = $this->getImageExtension($fileVersion->getName());
     return $image->get($imageExtension, $this->getOptionsFromImage($image, $imageExtension, $imagineOptions));
 }
开发者ID:sulu,项目名称:sulu,代码行数:36,代码来源:ImagineImageConverter.php

示例7: apply

 /**
  * @param BinaryInterface $binary
  * @param array $config
  *
  * @throws \InvalidArgumentException
  *
  * @return Binary
  */
 public function apply(BinaryInterface $binary, array $config)
 {
     $config = array_replace(array('filters' => array(), 'quality' => 100, 'animated' => false), $config);
     $image = $this->imagine->load($binary->getContent());
     foreach ($config['filters'] as $eachFilter => $eachOptions) {
         if (!isset($this->loaders[$eachFilter])) {
             throw new \InvalidArgumentException(sprintf('Could not find filter loader for "%s" filter type', $eachFilter));
         }
         $image = $this->loaders[$eachFilter]->load($image, $eachOptions);
     }
     $options = array('quality' => $config['quality']);
     if ($binary->getFormat() === 'gif' && $config['animated']) {
         $options['animated'] = $config['animated'];
     }
     $filteredContent = $image->get($binary->getFormat(), $options);
     return new Binary($filteredContent, $binary->getMimeType(), $binary->getFormat());
 }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:25,代码来源:FilterManager.php

示例8: drawImage

 /**
  * Draw $image on $this->resultImage.
  *
  * @param string $image Image blob.
  * @param Point  $point The point where to draw $image.
  *
  * @return void
  */
 protected function drawImage($image, Point $point)
 {
     try {
         $this->resultImage->paste($this->imagine->load($image), $point);
     } catch (\Exception $exception) {
         // Most likely an exception about a out of bounds past, we'll just ignore that
     }
 }
开发者ID:wyrihaximus,项目名称:staticmap,代码行数:16,代码来源:Renderer.php

示例9: find

 /**
  * {@inheritDoc}
  */
 public function find($path)
 {
     $name = $this->wrapperPrefix . $path;
     /*
      * This looks strange, but at least in PHP 5.3.8 it will raise an E_WARNING if the 4th parameter is null.
      * fopen() will be called only once with the correct arguments.
      *
      * The error suppression is solely to determine whether the file exists.
      * file_exists() is not used as not all wrappers support stat() to actually check for existing resources.
      */
     if ($this->context && !($resource = @fopen($name, 'r', null, $this->context)) || !($resource = @fopen($name, 'r'))) {
         throw new NotFoundHttpException('Source image not found.');
     }
     // Closing the opened stream to avoid locking of the resource to find.
     fclose($resource);
     return $this->imagine->load(file_get_contents($name, null, $this->context));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:20,代码来源:StreamLoader.php

示例10: loadImage

 /**
  * Loads an image from a file system path.
  *
  * @param string $path
  *
  * @throws Exception
  * @return Image
  */
 public function loadImage($path)
 {
     if (!IOHelper::fileExists($path)) {
         throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path)));
     }
     if (!craft()->images->checkMemoryForImage($path)) {
         throw new Exception(Craft::t("Not enough memory available to perform this image operation."));
     }
     $extension = IOHelper::getExtension($path);
     if ($extension === 'svg') {
         if (!craft()->images->isImagick()) {
             throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
         }
         $svg = IOHelper::getFileContents($path);
         if ($this->minSvgWidth !== null && $this->minSvgHeight !== null) {
             // Does the <svg> node contain valid `width` and `height` attributes?
             list($width, $height) = ImageHelper::parseSvgSize($svg);
             if ($width !== null && $height !== null) {
                 $scale = 1;
                 if ($width < $this->minSvgWidth) {
                     $scale = $this->minSvgWidth / $width;
                 }
                 if ($height < $this->minSvgHeight) {
                     $scale = max($scale, $this->minSvgHeight / $height);
                 }
                 $width = round($width * $scale);
                 $height = round($height * $scale);
                 if (preg_match(ImageHelper::SVG_WIDTH_RE, $svg) && preg_match(ImageHelper::SVG_HEIGHT_RE, $svg)) {
                     $svg = preg_replace(ImageHelper::SVG_WIDTH_RE, "\${1}{$width}px\"", $svg);
                     $svg = preg_replace(ImageHelper::SVG_HEIGHT_RE, "\${1}{$height}px\"", $svg);
                 } else {
                     $svg = preg_replace(ImageHelper::SVG_TAG_RE, "\${1} width=\"{$width}px\" height=\"{$height}px\" \${2}", $svg);
                 }
             }
         }
         try {
             $this->_image = $this->_instance->load($svg);
         } catch (\Imagine\Exception\RuntimeException $e) {
             // Invalid SVG. Maybe it's missing its DTD?
             $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $svg;
             $this->_image = $this->_instance->load($svg);
         }
     } else {
         $imageInfo = @getimagesize($path);
         if (!is_array($imageInfo)) {
             throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
         }
         $this->_image = $this->_instance->open($path);
     }
     $this->_extension = $extension;
     $this->_imageSourcePath = $path;
     if ($this->_extension == 'gif') {
         if (!craft()->images->isGd() && $this->_image->layers()) {
             $this->_isAnimatedGif = true;
         }
     }
     return $this;
 }
开发者ID:supercool,项目名称:Craft-Release,代码行数:66,代码来源:Image.php

示例11: apply

 /**
  * @param BinaryInterface $binary
  * @param array           $config
  *
  * @throws \InvalidArgumentException
  *
  * @return Binary
  */
 public function apply(BinaryInterface $binary, array $config)
 {
     $config = array_replace(array('filters' => array(), 'quality' => 100, 'animated' => false), $config);
     if ($binary instanceof FileBinaryInterface) {
         $image = $this->imagine->open($binary->getPath());
     } else {
         $image = $this->imagine->load($binary->getContent());
     }
     foreach ($config['filters'] as $eachFilter => $eachOptions) {
         if (!isset($this->loaders[$eachFilter])) {
             throw new \InvalidArgumentException(sprintf('Could not find filter loader for "%s" filter type', $eachFilter));
         }
         $prevImage = $image;
         $image = $this->loaders[$eachFilter]->load($image, $eachOptions);
         // If the filter returns a different image object destruct the old one because imagick keeps consuming memory if we don't
         // See https://github.com/liip/LiipImagineBundle/pull/682
         if ($prevImage !== $image && method_exists($prevImage, '__destruct')) {
             $prevImage->__destruct();
         }
     }
     $options = array('quality' => $config['quality']);
     if (isset($config['jpeg_quality'])) {
         $options['jpeg_quality'] = $config['jpeg_quality'];
     }
     if (isset($config['png_compression_level'])) {
         $options['png_compression_level'] = $config['png_compression_level'];
     }
     if (isset($config['png_compression_filter'])) {
         $options['png_compression_filter'] = $config['png_compression_filter'];
     }
     if ($binary->getFormat() === 'gif' && $config['animated']) {
         $options['animated'] = $config['animated'];
     }
     $filteredFormat = isset($config['format']) ? $config['format'] : $binary->getFormat();
     $filteredContent = $image->get($filteredFormat, $options);
     $filteredMimeType = $filteredFormat === $binary->getFormat() ? $binary->getMimeType() : $this->mimeTypeGuesser->guess($filteredContent);
     // We are done with the image object so we can destruct the this because imagick keeps consuming memory if we don't
     // See https://github.com/liip/LiipImagineBundle/pull/682
     if (method_exists($image, '__destruct')) {
         $image->__destruct();
     }
     return $this->applyPostProcessors(new Binary($filteredContent, $filteredMimeType, $filteredFormat), $config);
 }
开发者ID:raphydev,项目名称:onep,代码行数:51,代码来源:FilterManager.php

示例12: create

 /**
  * Creates an image object
  *
  * @param array|\Imagine\Image\ImageInterface $source
  * @throws \InvalidArgumentException On unsupported source type
  * @return \Imagine\Image\ImageInterface
  */
 public function create($source)
 {
     if ($source instanceof ImageInterface) {
         return $source;
     }
     if (isset($source['file'])) {
         return $this->imagine->open($source['file']);
     }
     if (isset($source['data'])) {
         return $this->imagine->load($source['data']);
     }
     if (isset($source['resource'])) {
         return $this->imagine->read($source['resource']);
     }
     if (isset($source['width']) && isset($source['height'])) {
         return $this->imagine->create(new Box($source['width'], $source['height']));
     }
     throw new InvalidArgumentException();
 }
开发者ID:phtamas,项目名称:yii2-imageprocessor,代码行数:26,代码来源:Component.php

示例13: loadFromSVG

 /**
  * Load an image from an SVG string.
  *
  * @param $svgContent
  *
  * @return Image
  */
 public function loadFromSVG($svgContent)
 {
     try {
         $this->_image = $this->_instance->load($svgContent);
     } catch (\Imagine\Exception\RuntimeException $e) {
         // Invalid SVG. Maybe it's missing its DTD?
         $svgContent = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $svgContent;
         $this->_image = $this->_instance->load($svgContent);
     }
     return $this;
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:18,代码来源:Image.php

示例14: setSizeWidthAndHeight

 /**
  * Set size of file, if it's image, set width and height.
  *
  * @param MediaInterface $media
  *
  * @return MediaInterface
  */
 public function setSizeWidthAndHeight(MediaInterface $media)
 {
     $key = $this->originalDir . '/' . $media->getReference();
     $media->setSize($this->filesystemManipulator->size($key));
     if ($media->getType() === $media::IMAGE) {
         $image = $this->imagine->load($this->filesystemManipulator->read($key));
         $size = $image->getSize();
         $media->setWidth($size->getWidth());
         $media->setHeight($size->getHeight());
     }
     return $this;
 }
开发者ID:Vooodoo,项目名称:MediaBundle,代码行数:19,代码来源:MediaManager.php

示例15: normalizeImage

 /**
  * {@inheritDoc}
  */
 public function normalizeImage($name, $content, $width, $height)
 {
     $extension = $this->getExtension($name);
     $image = $this->imagine->load($content);
     $size = $image->getSize();
     $box = new \Imagine\Image\Box($size->getWidth(), $size->getHeight());
     if ($size->getWidth() >= $size->getHeight() && $size->getWidth() > $width) {
         return $image->resize($box->widen($width))->get($extension);
     } elseif ($size->getWidth() < $size->getHeight() && $size->getHeight() > $height) {
         return $image->resize($box->heighten($height))->get($extension);
     }
     return $image->get($extension);
 }
开发者ID:thrace-project,项目名称:media-bundle,代码行数:16,代码来源:ImageManager.php


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