本文整理汇总了PHP中Imagine\Image\ImageInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ImageInterface类的具体用法?PHP ImageInterface怎么用?PHP ImageInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageInterface类的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: 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);
}
示例3: 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;
}
示例4: getColor
private function getColor(ImageInterface $image)
{
if ($this->color instanceof ColorInterface) {
return $this->color;
}
return $image->palette()->color($this->color);
}
示例5: apply
/**
* @param ImageInterface|\Imagine\Gmagick\Image $image
*
* @return ImageInterface
*/
public function apply(ImageInterface $image)
{
/** @var \Gmagick $gmagick */
$gmagick = $image->getGmagick();
$gmagick->reduceNoiseImage((double) $this->getOption('radius', 0));
return $image;
}
示例6: 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;
}
示例7: 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);
}
示例8: createFromImagine
/**
* @param ImageInterface $image
* @param $namespace
* @param $image_hash
* @param $image_thumb
* @return File
*/
public function createFromImagine(ImageInterface $image, $namespace, $image_hash, $image_thumb)
{
umask(00);
$dest = $this->createDestinationPath($namespace, $image_hash, $image_thumb);
$image->save($dest);
return new File($dest);
}
示例9: generateThumb
/**
* @param ImageInterface $image
* @return ImageInterface
*/
public function generateThumb(ImageInterface $image, $width, $height)
{
$background = isset($this->options["background"]) ? $this->options["background"] : null;
$fitSize = isset($this->options["fitSize"]) ? $this->options["fitSize"] : true;
$sizeBox = new Box($width, $height);
$thumbMode = ImageInterface::THUMBNAIL_INSET;
$thumb = $image->thumbnail($sizeBox, $thumbMode);
// fill the area
if ($fitSize) {
$palette = new RGB();
if (!$background || $background == "transparent") {
$backgroundColor = $palette->color("fff", 1);
} else {
$backgroundColor = $palette->color($background);
}
// source http://harikt.com/blog/2012/12/17/resize-image-keeping-aspect-ratio-in-imagine/
$realThumb = Image::create($sizeBox, $backgroundColor);
$sizeR = $thumb->getSize();
$widthR = $sizeR->getWidth();
$heightR = $sizeR->getHeight();
$startX = $startY = 0;
if ($widthR < $width) {
$startX = ($width - $widthR) / 2;
}
if ($heightR < $height) {
$startY = ($height - $heightR) / 2;
}
$realThumb->paste($thumb, new Point($startX, $startY));
} else {
$realThumb = $thumb;
}
return $realThumb;
}
示例10: apply
/**
* @param ImageInterface|\Imagine\Gmagick\Image $image
*
* @return ImageInterface
*/
public function apply(ImageInterface $image)
{
/** @var \Gmagick $gmagick */
$gmagick = $image->getGmagick();
$gmagick->swirlimage((double) $this->getOption('degrees', 60));
return $image;
}
示例11: createCache
/**
* {@inheritDoc}
*/
public function createCache($relativeName, $filter, ImageInterface $image, $formatOrImage = null, array $saveOptions = [])
{
$cachePath = $this->getCachePath($relativeName, $filter, $formatOrImage);
if (!is_dir(dirname($cachePath))) {
mkdir(dirname($cachePath), 0755, true);
}
$image->save($cachePath, $saveOptions);
}
示例12: load
public function load(ImageInterface $image, array $options = array())
{
if (empty($options)) {
throw new InvalidArgumentException('Missing width option');
}
$filter = new Gravity(new Box((int) $options[0], (int) $options[1]), new MiddleMiddle($image->getSize()));
$image = $filter->apply($image);
return $image;
}
示例13: 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;
}
示例14: load
/**
* {@inheritdoc}
*/
public function load(ImageInterface $image, array $options = array())
{
$mode = ImageInterface::INTERLACE_LINE;
if (!empty($options['mode'])) {
$mode = $options['mode'];
}
$image->interlace($mode);
return $image;
}
示例15: pasteCentered
protected function pasteCentered(\Imagine\Image\ImageInterface $image, \Imagine\Image\ImageInterface $original)
{
$originalSize = $original->getSize();
$x = $this->getPasteValue($this->size->getWidth(), $originalSize->getWidth());
$y = $this->getPasteValue($this->size->getHeight(), $originalSize->getHeight());
$pastePoint = new \Imagine\Image\Point($x, $y);
$image->paste($original, $pastePoint);
return $image;
}