本文整理汇总了PHP中Imagine\Image\ImageInterface::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageInterface::getSize方法的具体用法?PHP ImageInterface::getSize怎么用?PHP ImageInterface::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imagine\Image\ImageInterface
的用法示例。
在下文中一共展示了ImageInterface::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cropImage
/**
* Crop image if exceeds boundaries
*
* @param ImageInterface $image
* @param $settings
* @return ImageInterface
*/
private function cropImage(ImageInterface $image, $settings)
{
$neededSize = new Box($settings['width'], $settings['height']);
$currentSize = $image->getSize();
if ($neededSize->contains($currentSize)) {
return $image;
}
$point = new Point($currentSize->getWidth() > $neededSize->getWidth() ? round(($currentSize->getWidth() - $neededSize->getWidth()) / 2) : 0, $currentSize->getHeight() > $neededSize->getHeight() ? round(($currentSize->getHeight() - $neededSize->getHeight()) / 2) : 0);
$image->crop($point, $neededSize);
return $image;
}
示例2: apply
/**
* Applies scheduled transformation to ImageInterface instance
* Returns processed ImageInterface instance
*
* @param \Imagine\Image\ImageInterface $image
*
* @return \Imagine\Image\ImageInterface
*/
function apply(ImageInterface $image)
{
// We reduce the usage of methods on the image to dramatically increase the performance of this algorithm.
// Really... We need that performance...
// Therefore we first build a matrix, that holds the colors of the image.
$width = $image->getSize()->getWidth();
$height = $image->getSize()->getHeight();
$byteData = new Matrix($width, $height);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$byteData->setElementAt($x, $y, $image->getColorAt(new Point($x, $y)));
}
}
$dHeight = (int) floor(($this->matrix->getHeight() - 1) / 2);
$dWidth = (int) floor(($this->matrix->getWidth() - 1) / 2);
for ($y = $dHeight; $y < $height - $dHeight; $y++) {
for ($x = $dWidth; $x < $width - $dWidth; $x++) {
$sumRed = 0;
$sumGreen = 0;
$sumBlue = 0;
// calculate new color
for ($boxX = $x - $dWidth, $matrixX = 0; $boxX <= $x + $dWidth; $boxX++, $matrixX++) {
for ($boxY = $y - $dHeight, $matrixY = 0; $boxY <= $y + $dHeight; $boxY++, $matrixY++) {
$sumRed = $sumRed + $this->matrix->getElementAt($matrixX, $matrixY) * $byteData->getElementAt($boxX, $boxY)->getRed();
$sumGreen = $sumGreen + $this->matrix->getElementAt($matrixX, $matrixY) * $byteData->getElementAt($boxX, $boxY)->getGreen();
$sumBlue = $sumBlue + $this->matrix->getElementAt($matrixX, $matrixY) * $byteData->getElementAt($boxX, $boxY)->getBlue();
}
}
// set new color - has to be between 0 and 255!
$image->draw()->dot(new Point($x, $y), new Color(array('red' => max(0, min(255, $sumRed)), 'green' => max(0, min(255, $sumGreen)), 'blue' => max(0, min(255, $sumBlue)))));
}
}
return $image;
}
示例3: execute
/**
* {@inheritdoc}
*/
public function execute(ImageInterface $image, $parameters)
{
$maskPath = isset($parameters['image']) ? $this->fileLocator->locate($parameters['image']) : null;
if (!$maskPath) {
return $image;
}
$originalWidth = $image->getSize()->getWidth();
$originalHeight = $image->getSize()->getHeight();
$top = isset($parameters['top']) ? $parameters['top'] : 0;
$left = isset($parameters['left']) ? $parameters['left'] : 0;
$width = isset($parameters['width']) ? $parameters['width'] : $originalWidth;
$height = isset($parameters['height']) ? $parameters['height'] : $originalHeight;
// imagine will error when mask is bigger then the given image
// this could happen in forceRatio true mode so we need also scale the mask
if ($width > $originalWidth) {
$width = $originalWidth;
$height = (int) ($height / $width * $originalWidth);
}
if ($height > $originalHeight) {
$height = $originalHeight;
$width = (int) ($width / $height * $originalHeight);
}
// create mask
$mask = $this->createMask($maskPath, $width, $height);
// add mask to image
$image->paste($mask, new Point($top, $left));
return $image;
}
示例4: apply
/**
* Applies scheduled transformation to ImageInterface instance
* Returns processed ImageInterface instance
*
* @param ImageInterface $image
*
* @return ImageInterface
*/
public function apply(ImageInterface $image)
{
for ($x = 0; $x < $image->getSize()->getWidth(); $x++) {
for ($y = 0; $y < $image->getSize()->getHeight(); $y++) {
call_user_func($this->callback, $image, new Point($x, $y));
}
}
return $image;
}
示例5: stringYtoInteger
/**
* @param string $point
* @param \Imagine\Image\ImageInterface $pasteImage
* @param \Imagine\Image\ImageInterface $image
*
* @return integer
*/
protected function stringYtoInteger($point, ImageInterface $pasteImage, ImageInterface $image)
{
switch ($point) {
case 'bottom':
return (int) $image->getSize()->getHeight() - $pasteImage->getSize()->getHeight();
case 'middle':
return (int) round($image->getSize()->getHeight() / 2 - $pasteImage->getSize()->getHeight() / 2);
case 'top':
}
}
示例6: calculateDimensions
protected function calculateDimensions($width = null, $height = null)
{
if (empty($width)) {
$width = $this->image->getSize()->getWidth();
}
if (empty($height)) {
$height = $this->image->getSize()->getHeight();
}
$this->width = $width;
$this->height = $height;
}
示例7: load
/**
* {@inheritDoc}
*/
public function load(ImageInterface $image, array $options = array())
{
$background = $image->palette()->color(isset($options['color']) ? $options['color'] : '#fff', isset($options['transparency']) ? $options['transparency'] : null);
$topLeft = new Point(0, 0);
$size = $image->getSize();
if (isset($options['size'])) {
list($width, $height) = $options['size'];
$size = new Box($width, $height);
$topLeft = new Point(($width - $image->getSize()->getWidth()) / 2, ($height - $image->getSize()->getHeight()) / 2);
}
$canvas = $this->imagine->create($size, $background);
return $canvas->paste($image, $topLeft);
}
示例8: isInsideImage
/**
* Returns true iff the cropping does not exceed the image borders.
*
* @param ImageInterface $image
* @param $x
* @param $y
* @param $width
* @param $height
*
* @return bool
*/
private function isInsideImage(ImageInterface $image, $x, $y, $width, $height)
{
if ($x < 0 || $y < 0) {
return false;
}
if ($x + $width > $image->getSize()->getWidth()) {
return false;
}
if ($y + $height > $image->getSize()->getHeight()) {
return false;
}
return true;
}
示例9: updateFile
/**
* @param ImagineImageInterface $image
*
* @return ImagineImageInterface
*/
public function updateFile(ImagineImageInterface $image)
{
$this->originWidth = $image->getSize()->getWidth();
$this->originHeight = $image->getSize()->getHeight();
// Resize
$this->resize();
$resize = new ImagineResize(new Box($this->resizeWidth, $this->resizeHeight));
$image = $resize->apply($image);
// Crop
$this->crop();
$crop = new ImagineCrop(new Point($this->targetLeft, $this->targetTop), new Box($this->targetWidth, $this->targetHeight));
$image = $crop->apply($image);
return $image;
}
示例10: apply
/**
* {@inheritDoc}
*/
public function apply(ImageInterface $image)
{
if ($this->size) {
list($width, $height) = $this->size;
$size = new Box($width, $height);
$topLeft = new Point(($width - $image->getSize()->getWidth()) / 2, ($height - $image->getSize()->getHeight()) / 2);
} else {
$topLeft = new Point(0, 0);
$size = $image->getSize();
}
$background = $image->palette()->color($this->color);
$canvas = $this->imagine->create($size, $background);
return $canvas->paste($image, $topLeft);
}
示例11: load
/**
* {@inheritDoc}
*/
public function load(ImageInterface $image, array $options = array())
{
if (!isset($options['min'])) {
throw new \InvalidArgumentException('Missing min option.');
}
list($width, $height) = $options['min'];
$size = $image->getSize();
$origWidth = $size->getWidth();
$origHeight = $size->getHeight();
if ($origWidth < $width || $origHeight < $height) {
$widthRatio = $width / $origWidth;
$heightRatio = $height / $origHeight;
$ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio;
$filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio));
return $filter->apply($image);
}
return $image;
}
示例12: load
/**
* {@inheritdoc}
*/
public function load(ImageInterface $image, array $options = array())
{
$mode = ImageInterface::THUMBNAIL_OUTBOUND;
if (!empty($options['mode']) && 'inset' === $options['mode']) {
$mode = ImageInterface::THUMBNAIL_INSET;
}
if (!empty($options['filter'])) {
$filter = constant('Imagine\\Image\\ImageInterface::FILTER_' . strtoupper($options['filter']));
}
if (empty($filter)) {
$filter = ImageInterface::FILTER_UNDEFINED;
}
list($width, $height) = $options['size'];
$size = $image->getSize();
$origWidth = $size->getWidth();
$origHeight = $size->getHeight();
if (null === $width || null === $height) {
if (null === $height) {
$height = (int) ($width / $origWidth * $origHeight);
} elseif (null === $width) {
$width = (int) ($height / $origHeight * $origWidth);
}
}
if ($origWidth > $width || $origHeight > $height || !empty($options['allow_upscale']) && ($origWidth !== $width || $origHeight !== $height)) {
$filter = new Thumbnail(new Box($width, $height), $mode, $filter);
$image = $filter->apply($image);
}
return $image;
}
示例13: load
/**
* {@inheritDoc}
*/
public function load(ImageInterface $image, array $options = array())
{
$background = new Color(isset($options['color']) ? $options['color'] : '#fff');
$topLeft = new Point(0, 0);
$canvas = $this->imagine->create($image->getSize(), $background);
return $canvas->paste($image, $topLeft);
}
示例14: 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);
}
示例15: imageResize
/**
* @return null|string
*/
public function imageResize()
{
$this->openImage();
$width = $this->imageWidth;
$height = $this->imageHeight;
$maxWidth = $this->imageMaxWidth;
$maxHeight = $this->imageMaxHeight;
if ($maxWidth === null && $maxHeight !== null) {
$imageBox = $this->image->getSize()->heighten($maxHeight);
} elseif ($maxHeight === null && $maxWidth !== null) {
$imageBox = $this->image->getSize()->widen($maxWidth);
} elseif ($maxHeight !== null && $maxWidth !== null) {
$imageBox = $this->image->getSize()->heighten($maxHeight)->widen($maxWidth);
} elseif ($width !== null && $height !== null) {
$imageBox = new \Imagine\Image\Box($width, $height);
} elseif ($width === null && $height !== null) {
$imageBox = new \Imagine\Image\Box($this->image->getSize()->getWidth(), $height);
} elseif ($width !== null && $height === null) {
$imageBox = new \Imagine\Image\Box($width, $this->image->getSize()->getHeight());
} else {
$imageBox = new \Imagine\Image\Box($this->image->getSize()->getWidth(), $this->image->getSize()->getHeight());
}
$this->image = $this->image->resize($imageBox);
return $this;
}