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


PHP BoxInterface::getHeight方法代码示例

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


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

 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     $currentSize = $image->getSize();
     $ratioCurrent = $currentSize->getHeight() / $currentSize->getWidth();
     $ratioNew = $this->size->getHeight() / $this->size->getWidth();
     // ratio inverse of original and thumb image
     $ratioInverseNew = 1 / $ratioNew;
     // image has to crop
     if ($ratioCurrent != $ratioNew) {
         if ($this->size->getWidth() > $this->size->getHeight()) {
             $cropHeight = $currentSize->getWidth() * $ratioNew;
             $cropWidth = $currentSize->getWidth();
             if ($cropHeight > $currentSize->getHeight()) {
                 $correction = 1 / ($cropHeight / $currentSize->getHeight());
                 $cropWidth *= $correction;
                 $cropHeight *= $correction;
             }
         } else {
             $cropWidth = $currentSize->getHeight() * $ratioInverseNew;
             $cropHeight = $currentSize->getHeight();
             if ($cropWidth > $currentSize->getWidth()) {
                 $correction = 1 / ($cropWidth / $currentSize->getWidth());
                 $cropWidth *= $correction;
                 $cropHeight *= $correction;
             }
         }
         $cropSize = new Box($cropWidth, $cropHeight);
         $startPoint = $this->gravity->getStartPoint($cropSize);
         $image = $image->crop($startPoint, $cropSize);
     }
     return $image->resize($this->size);
 }
开发者ID:shapecode,项目名称:imagine-thumbnail-gravity-filter,代码行数:35,代码来源:ThumbnailGravity.php

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: makeTextFitInBox

 /**
  * 
  * @param \Imagine\Image\BoxInterface $box
  * @return \Imagine\Image\BoxInterface 
  */
 public function makeTextFitInBox(BoxInterface $box)
 {
     $lines = array();
     $currentLine = array();
     $fontSize = $this->font->getSize();
     while (true) {
         $font = new Font($this->im, $this->font->getFile(), $fontSize, $this->font->getColor());
         $lines = array();
         $currentLine = array();
         $splitString = explode(' ', $this->string);
         while (count($splitString) != 0) {
             $firstWord = $splitString[0];
             if ($font->box($firstWord)->getWidth() > $box->getWidth()) {
                 $lines[] = array_shift($splitString);
                 continue;
             }
             $newCurrentLine = $currentLine;
             $newCurrentLine[] = $firstWord;
             $str = implode(' ', $newCurrentLine);
             $newBox = $font->box($str);
             if ($newBox->getWidth() < $box->getWidth()) {
                 $currentLine[] = array_shift($splitString);
             } else {
                 $lines[] = $currentLine;
                 $currentLine = array();
             }
         }
         $lines[] = $currentLine;
         if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
             $offsetY = 96 / 72;
         } else {
             $offsetY = 1;
         }
         if (count($lines) * $font->getSize() * $offsetY < $box->getHeight()) {
             break;
         }
         $fontSize -= 2;
         if ($fontSize <= 0) {
             throw new \LogicException('Font cannot be smaller than 0');
         }
     }
     $this->font = $font;
     $this->lines = $this->mergeWordsInLines($lines);
     return $font->box($this->string);
 }
开发者ID:piotrbelina,项目名称:memegenerator,代码行数:50,代码来源:Fitter.php

示例15: 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


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