• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Image\BoxInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Imagine\Image\BoxInterface的典型用法代码示例。如果您正苦于以下问题:PHP BoxInterface类的具体用法?PHP BoxInterface怎么用?PHP BoxInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: getHeightWidth

 /**
  * @param $parameters
  * @param \Imagine\Image\BoxInterface $size
  *
  * @return array
  */
 protected function getHeightWidth($parameters, $size)
 {
     $newWidth = $parameters['x'];
     $newHeight = $parameters['y'];
     // retina x2
     if ($parameters['retina']) {
         $newWidth = $parameters['x'] * 2;
         $newHeight = $parameters['x'] * 2;
     }
     // calculate height when not set
     if (!$newHeight) {
         $newHeight = $size->getHeight() / $size->getWidth() * $newWidth;
     }
     // calculate width when not set
     if (!$newWidth) {
         $newWidth = $size->getWidth() / $size->getHeight() * $newHeight;
     }
     // if image is smaller keep ratio
     // e.g. when a square image is requested (200x200) and the original image is smaller (150x100)
     //      it still returns a squared image (100x100)
     if ($parameters['forceRatio']) {
         if ($newWidth > $size->getWidth()) {
             list($newHeight, $newWidth) = $this->getSizeInSameRatio($newHeight, $newWidth, $size->getWidth());
         }
         if ($newHeight > $size->getHeight()) {
             list($newWidth, $newHeight) = $this->getSizeInSameRatio($newWidth, $newHeight, $size->getHeight());
         }
     }
     return [$newWidth, $newHeight];
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:36,代码来源:ScaleCommand.php


示例2: create

 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     if ($color === null) {
         $palette = self::$rgb;
         $color = '#ffffff';
         $alpha = 0;
     } else {
         $palette = $color->getPalette();
         $alpha = $color->getAlpha() / 100;
     }
     try {
         $pixel = new \GmagickPixel((string) $color);
         $pixel->setcolorvalue(\Gmagick::COLOR_OPACITY, $alpha);
         // does nothing as of Gmagick 1.1.7RC2.  Background will be fully opaque.
         $magick = new \Gmagick();
         $magick->newimage($width, $height, $pixel->getcolor(false));
         $magick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
         $magick->setimagebackgroundcolor($pixel);
         return new RImage($magick, $palette, self::$emptyBag, array($width, $height));
     } catch (\Exception $e) {
         throw new \Imagine\Exception\RuntimeException("Gmagick: could not create empty image. {$e->getMessage()}", $e->getCode(), $e);
     }
 }
开发者ID:raadhuis,项目名称:modx-basic,代码行数:25,代码来源:RImagine.php


示例3: create

    /**
     * (non-PHPdoc)
     * @see Imagine\Image\ImagineInterface::create()
     */
    public function create(BoxInterface $size, Color $color = null)
    {
        $width  = $size->getWidth();
        $height = $size->getHeight();

        $color = null !== $color ? $color : new Color('fff');

        try {
            $pixel = new \ImagickPixel((string) $color);
            $pixel->setColorValue(
                \Imagick::COLOR_OPACITY,
                number_format(abs(round($color->getAlpha() / 100, 1)), 1)
            );

            $imagick = new \Imagick();
            $imagick->newImage($width, $height, $pixel);
            $imagick->setImageMatte(true);
            $imagick->setImageBackgroundColor($pixel);

            $pixel->clear();
            $pixel->destroy();

            return new Image($imagick);
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Could not create empty image', $e->getCode(), $e
            );
        }
    }
开发者ID:ndusan,项目名称:bginfobox,代码行数:33,代码来源:Imagine.php


示例4: create

 /**
  * (non-PHPdoc)
  * @see Imagine\Image\ImagineInterface::create()
  */
 public function create(BoxInterface $size, Color $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $resource = imagecreatetruecolor($width, $height);
     if (false === $resource) {
         throw new RuntimeException('Create operation failed');
     }
     $color = $color ? $color : new Color('fff');
     if (false === imagealphablending($resource, false) || false === imagesavealpha($resource, true)) {
         throw new RuntimeException('Could not set alphablending, savealpha and antialias values');
     }
     if (function_exists('imageantialias')) {
         imageantialias($resource, true);
     }
     $index = imagecolorallocatealpha($resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100));
     if (false === $index) {
         throw new RuntimeException('Unable to allocate color');
     }
     if (false === imagefill($resource, 0, 0, $index)) {
         throw new RuntimeException('Could not set background color fill');
     }
     if ($color->getAlpha() >= 95) {
         imagecolortransparent($resource, $index);
     }
     return new Image($resource, $this);
 }
开发者ID:SerdarSanri,项目名称:laravel-imagine-bundle,代码行数:31,代码来源:Imagine.php


示例5: create

 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $resource = imagecreatetruecolor($width, $height);
     if (false === $resource) {
         throw new RuntimeException('Create operation failed');
     }
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = $color ? $color : $palette->color('fff');
     if (!$color instanceof RGBColor) {
         throw new InvalidArgumentException('GD driver only supports RGB colors');
     }
     $index = imagecolorallocatealpha($resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100));
     if (false === $index) {
         throw new RuntimeException('Unable to allocate color');
     }
     if (false === imagefill($resource, 0, 0, $index)) {
         throw new RuntimeException('Could not set background color fill');
     }
     if ($color->getAlpha() >= 95) {
         imagecolortransparent($resource, $index);
     }
     return $this->wrap($resource, $palette);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:28,代码来源:Imagine.php


示例6: create

 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = null !== $color ? $color : $palette->color('fff');
     try {
         $gmagick = new \Gmagick();
         // Gmagick does not support creation of CMYK GmagickPixel
         // see https://bugs.php.net/bug.php?id=64466
         if ($color instanceof CMYKColor) {
             $switchPalette = $palette;
             $palette = new RGB();
             $pixel = new \GmagickPixel($palette->color((string) $color));
         } else {
             $switchPalette = null;
             $pixel = new \GmagickPixel((string) $color);
         }
         if ($color->getPalette()->supportsAlpha() && $color->getAlpha() < 100) {
             throw new NotSupportedException('alpha transparency is not supported');
         }
         $gmagick->newimage($width, $height, $pixel->getcolor(false));
         $gmagick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
         $gmagick->setimagebackgroundcolor($pixel);
         $image = new Image($gmagick, $palette, new MetadataBag());
         if ($switchPalette) {
             $image->usePalette($switchPalette);
         }
         return $image;
     } catch (\GmagickException $e) {
         throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
     }
 }
开发者ID:raadhuis,项目名称:modx-basic,代码行数:36,代码来源:Imagine.php


示例7: scaleSize

 /**
  * Modifies $width or $height (if one of them is empty) based on $box ratio.
  * @param number|null $width Desired width
  * @param number|null $height Desired height
  * @param \Imagine\Image\BoxInterface $box Original box for a reference
  */
 public static function scaleSize(&$width, &$height, \Imagine\Image\BoxInterface $box)
 {
     if (!$width || !$height) {
         $r = $box->getWidth() / $box->getHeight();
         if ($width) {
             $height = floor($width / $r);
         } else {
             $width = floor($height * $r);
         }
     }
 }
开发者ID:x000000,项目名称:storage-manager,代码行数:17,代码来源:Helper.php


示例8: calculateRatio

 /**
  * @param BoxInterface $imageSize
  * @param array $settings
  * @return array|mixed
  */
 private function calculateRatio(BoxInterface $imageSize, array $settings)
 {
     $ratio = array();
     if ($settings['height']) {
         $ratio[] = $settings['height'] / $imageSize->getHeight();
     }
     if ($settings['width']) {
         $ratio[] = $settings['width'] / $imageSize->getWidth();
     }
     $ratio = max($ratio);
     return $ratio;
 }
开发者ID:xaben,项目名称:XabenMediaBundle,代码行数:17,代码来源:OutboundResizer.php


示例9: crop

 public function crop(PointInterface $start, BoxInterface $size)
 {
     if ($this->image === null) {
         $this->load();
     }
     $width = $size->getWidth();
     $height = $size->getHeight();
     try {
         $this->image->getGmagick()->cropimage($width, $height, $start->getX(), $start->getY());
     } catch (\GmagickException $e) {
         throw new \Imagine\Exception\RuntimeException("Gmagick: Crop operation failed. {$e->getMessage()}", $e->getCode(), $e);
     }
     $this->size = array($width, $height);
     return $this;
 }
开发者ID:raadhuis,项目名称:modx-basic,代码行数:15,代码来源:RImage.php


示例10: testGrayscaling

 /**
  * @covers \Imagine\Filter\Advanced\Grayscale::apply
  *
  * @dataProvider getDataSet
  *
  * @param \Imagine\Image\BoxInterface $size
  * @param \Imagine\Image\Color $color
  * @param \Imagine\Image\Color $filteredColor
  */
 public function testGrayscaling(BoxInterface $size, Color $color, Color $filteredColor)
 {
     $image = $this->getImage();
     $imageWidth = $size->getWidth();
     $imageHeight = $size->getHeight();
     $size = $this->getMock('Imagine\\Image\\BoxInterface');
     $size->expects($this->exactly($imageWidth + 1))->method('getWidth')->will($this->returnValue($imageWidth));
     $size->expects($this->exactly($imageWidth * ($imageHeight + 1)))->method('getHeight')->will($this->returnValue($imageHeight));
     $image->expects($this->any())->method('getSize')->will($this->returnValue($size));
     $image->expects($this->exactly($imageWidth * $imageHeight))->method('getColorAt')->will($this->returnValue($color));
     $draw = $this->getDrawer();
     $draw->expects($this->exactly($imageWidth * $imageHeight))->method('dot')->with($this->isInstanceOf('Imagine\\Image\\Point'), $this->equalTo($filteredColor));
     $image->expects($this->exactly($imageWidth * $imageHeight))->method('draw')->will($this->returnValue($draw));
     $filter = new Grayscale();
     $this->assertSame($image, $filter->apply($image));
 }
开发者ID:Laxman-SM,项目名称:iron_worker_examples,代码行数:25,代码来源:GrayscaleTest.php


示例11: create

 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     if (null !== $color) {
         throw new InvalidArgumentException('Imagine SVG does not support colors');
     }
     $document = new \DOMDocument();
     $svg = $document->createElementNS('http://www.w3.org/2000/svg', 'svg');
     $svg->setAttribute('version', '1.1');
     if ($size->getWidth()) {
         $svg->setAttribute('width', $size->getWidth());
     }
     if ($size->getHeight()) {
         $svg->setAttribute('height', $size->getHeight());
     }
     $document->appendChild($svg);
     return new Image($document, new MetadataBag());
 }
开发者ID:contao,项目名称:imagine-svg,代码行数:20,代码来源:Imagine.php


示例12: positionLayerOnCanvas

 /**
  * Calculates coordinates of top left corner of layer that should be positioned on canvas using given
  * vertical and horizontal positions.
  *
  * @param BoxInterface      $canvas_size         Size of canvas
  * @param BoxInterface      $layer_size          Size of layer
  * @param string            $horizontal_position left|center|right
  * @param string            $vertical_position   top|center|bottom
  * @param BoxInterface|null $padding             Optional padding between canvas and layer sides.
  *
  * @return Point
  */
 public static function positionLayerOnCanvas(BoxInterface $canvas_size, BoxInterface $layer_size, $horizontal_position, $vertical_position, BoxInterface $padding = null)
 {
     $dest_x = $dest_y = 0;
     $original_width = $canvas_size->getWidth();
     $original_height = $canvas_size->getHeight();
     if ($padding instanceof BoxInterface) {
         $delta_x = $padding->getWidth();
         $delta_y = $padding->getHeight();
     } else {
         $delta_x = 0;
         $delta_y = 0;
     }
     $new_wt_width = $layer_size->getWidth();
     $new_wt_height = $layer_size->getHeight();
     if ($new_wt_width + $delta_x > $original_width) {
         $new_wt_height = $new_wt_height * ($original_width - $delta_x) / $new_wt_width;
         $new_wt_width = $original_width - $delta_x;
     }
     if ($new_wt_height > $original_height) {
         $new_wt_width = $new_wt_width * ($original_height - $delta_y) / $new_wt_height;
         $new_wt_height = $original_height - $delta_y;
     }
     if ($vertical_position == 'top') {
         $dest_y = $delta_y;
     } elseif ($vertical_position == 'center') {
         $dest_y = (int) (($original_height - $new_wt_height) / 2);
     } elseif ($vertical_position == 'bottom') {
         $dest_y = $original_height - $new_wt_height - $delta_y;
     }
     if ($horizontal_position == 'left') {
         $dest_x = $delta_x;
     } elseif ($horizontal_position == 'center') {
         $dest_x = (int) (($original_width - $new_wt_width) / 2);
     } elseif ($horizontal_position == 'right') {
         $dest_x = $original_width - $new_wt_width - $delta_x;
     }
     if ($dest_x < 1) {
         $dest_x = 0;
     }
     if ($dest_y < 1) {
         $dest_y = 0;
     }
     return new Point($dest_x, $dest_y);
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:56,代码来源:ImageHelper.php


示例13: getPathFilter

 /**
  * @param array | BoxInterface $data
  *
  * @throws \Zf2FileUploader\Filter\Thumbnail\Exception\InvalidArgumentException
  * @return PathFilter
  */
 public function getPathFilter($data)
 {
     if ($data instanceof BoxInterface) {
         $width = $data->getWidth();
         $height = $data->getHeight();
     } else {
         if (func_num_args() > 1) {
             list($width, $height) = func_get_args();
         } else {
             if (is_array($data) && array_key_exists('width', $data) && array_key_exists('height', $data) || preg_match('/^(?P<width>[0-9]+)x(?P<height>[0-9]+)$/', $data, $data)) {
                 $width = $data['width'];
                 $height = $data['height'];
             } else {
                 throw new Exception\InvalidArgumentException("Could not retrieve width and height from data");
             }
         }
     }
     return new PathFilter($width, $height);
 }
开发者ID:spalax,项目名称:zf2-file-uploader,代码行数:25,代码来源:PathFilterFactory.php


示例14: isEqualTo

 /**
  * {@inheritdoc}
  */
 public function isEqualTo($coordinates)
 {
     if ($coordinates instanceof BoxInterface) {
         $coordinates = new static($coordinates, new Point(0, 0), $coordinates);
     }
     if (!$coordinates instanceof ResizeCoordinatesInterface) {
         throw new \InvalidArgumentException(sprintf('$coordinates must be an instance of ResizeCoordinatesInterface or BoxInterface, "%s" given', get_class($coordinates)));
     }
     /* @var ResizeCoordinatesInterface $coordinates */
     return $this->cropStart->getX() === $coordinates->getCropStart()->getX() && $this->cropStart->getY() === $coordinates->getCropStart()->getY() && $this->cropSize->getWidth() === $coordinates->getCropSize()->getWidth() && $this->cropSize->getHeight() === $coordinates->getCropSize()->getHeight() && $this->size->getWidth() === $coordinates->getSize()->getWidth() && $this->size->getHeight() === $coordinates->getSize()->getHeight();
 }
开发者ID:contao,项目名称:image,代码行数:14,代码来源:ResizeCoordinates.php


示例15: resize

 /**
  * resizes image using a focal point
  * @param  ImageInterface $image  an Imagine image
  * @param  BoxInterface   $size   size of resized imaga
  * @param  FocalPoint     $focal  focal point to use for size
  * @param  string         $filter Imagine filter to use
  * @return ImageInterface resized image
  */
 public function resize(ImageInterface $image, BoxInterface $size, FocalPointInterface $focal, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     $origSize = $image->getSize();
     $origWidth = $origSize->getWidth();
     $origHeight = $origSize->getHeight();
     $width = $size->getWidth();
     $height = $size->getHeight();
     $ratioHeight = $origHeight / $height;
     $ratioWidth = $origWidth / $width;
     if ($ratioHeight < $ratioWidth) {
         list($cropX1, $cropX2) = $this->calculateCrop($origWidth, $width, $focal->getX(), $ratioHeight);
         $cropY1 = 0;
         $cropY2 = $origHeight;
     } else {
         list($cropY1, $cropY2) = $this->calculateCrop($origHeight, $height, -$focal->getY(), $ratioWidth);
         $cropX1 = 0;
         $cropX2 = $origWidth;
     }
     $image->crop(new Point($cropX1, $cropY1), new Box($cropX2 - $cropX1, $cropY2 - $cropY1))->resize(new Box($width, $height, $filter));
     return $image;
 }
开发者ID:maagi,项目名称:imagine-focalresizer,代码行数:29,代码来源:Resizer.php


示例16: thumbnail

 /**
  * {@inheritdoc}
  */
 public function thumbnail(BoxInterface $size, $mode = ImageInterface::THUMBNAIL_INSET, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     if ($mode !== ImageInterface::THUMBNAIL_INSET && $mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
         throw new InvalidArgumentException('Invalid mode specified');
     }
     $imageSize = $this->getSize();
     $ratios = array($size->getWidth() / $imageSize->getWidth(), $size->getHeight() / $imageSize->getHeight());
     $thumbnail = $this->copy();
     $thumbnail->usePalette($this->palette());
     $thumbnail->strip();
     // if target width is larger than image width
     // AND target height is longer than image height
     if ($size->contains($imageSize)) {
         return $thumbnail;
     }
     if ($mode === ImageInterface::THUMBNAIL_INSET) {
         $ratio = min($ratios);
     } else {
         $ratio = max($ratios);
     }
     if ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
         if (!$imageSize->contains($size)) {
             $size = new Box(min($imageSize->getWidth(), $size->getWidth()), min($imageSize->getHeight(), $size->getHeight()));
         } else {
             $imageSize = $thumbnail->getSize()->scale($ratio);
             $thumbnail->resize($imageSize, $filter);
         }
         $thumbnail->crop(new Point(max(0, round(($imageSize->getWidth() - $size->getWidth()) / 2)), max(0, round(($imageSize->getHeight() - $size->getHeight()) / 2))), $size);
     } else {
         if (!$imageSize->contains($size)) {
             $imageSize = $imageSize->scale($ratio);
             $thumbnail->resize($imageSize, $filter);
         } else {
             $imageSize = $thumbnail->getSize()->scale($ratio);
             $thumbnail->resize($imageSize, $filter);
         }
     }
     return $thumbnail;
 }
开发者ID:Danack,项目名称:Imagine,代码行数:42,代码来源:AbstractImage.php


示例17: create

 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = null !== $color ? $color : $palette->color('fff');
     try {
         $pixel = new \ImagickPixel((string) $color);
         $pixel->setColorValue(Imagick::COLOR_ALPHA, $color->getAlpha() / 100);
         $imagick = new Imagick();
         $imagick->newImage($width, $height, $pixel);
         $imagick->setImageMatte(true);
         $imagick->setImageBackgroundColor($pixel);
         if (version_compare('6.3.1', $this->getVersion($imagick)) < 0) {
             $imagick->setImageOpacity($pixel->getColorValue(Imagick::COLOR_ALPHA));
         }
         $pixel->clear();
         $pixel->destroy();
         return new Image($imagick, $palette, new MetadataBag());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
     }
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:26,代码来源:Imagine.php


示例18: in

 /**
  * {@inheritdoc}
  */
 public function in(BoxInterface $box)
 {
     return $this->x < $box->getWidth() && $this->y < $box->getHeight();
 }
开发者ID:sergiimazurok,项目名称:koziuck,代码行数:7,代码来源:Point.php


示例19: resize

 /**
  * {@inheritdoc}
  *
  * @return ImageInterface
  */
 public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     try {
         $this->imagick->resizeImage($size->getWidth(), $size->getHeight(), $this->getFilter($filter), 1);
     } catch (\ImagickException $e) {
         throw new RuntimeException('Resize operation failed', $e->getCode(), $e);
     }
     return $this;
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:14,代码来源:Image.php


示例20: createImage

 /**
  * Internal
  *
  * Generates a GD image
  *
  * @param BoxInterface $size
  * @param  string the operation initiating the creation
  *
  * @return resource
  *
  * @throws RuntimeException
  *
  */
 private function createImage(BoxInterface $size, $operation)
 {
     $resource = imagecreatetruecolor($size->getWidth(), $size->getHeight());
     if (false === $resource) {
         throw new RuntimeException('Image ' . $operation . ' failed');
     }
     if (false === imagealphablending($resource, false) || false === imagesavealpha($resource, true)) {
         throw new RuntimeException('Image ' . $operation . ' failed');
     }
     if (function_exists('imageantialias')) {
         imageantialias($resource, true);
     }
     $transparent = imagecolorallocatealpha($resource, 255, 255, 255, 127);
     imagefill($resource, 0, 0, $transparent);
     imagecolortransparent($resource, $transparent);
     return $resource;
 }
开发者ID:jewelhuq,项目名称:fraym,代码行数:30,代码来源:Image.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Image\ImageInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Gd\Imagine类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap