本文整理汇总了PHP中Imagine\Image\ImageInterface::palette方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageInterface::palette方法的具体用法?PHP ImageInterface::palette怎么用?PHP ImageInterface::palette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imagine\Image\ImageInterface
的用法示例。
在下文中一共展示了ImageInterface::palette方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getColor
private function getColor(ImageInterface $image)
{
if ($this->color instanceof ColorInterface) {
return $this->color;
}
return $image->palette()->color($this->color);
}
示例2: imageColorize
/**
* Command image colorize
*
* @param string $hexColor
*
* @return void
*/
protected function imageColorize($hexColor)
{
if (strlen($hexColor) != 6 || !preg_match('![0-9abcdef]!i', $hexColor)) {
throw new BadMethodCallException('Invalid parameter color for command "colorize"');
}
$color = $this->image->palette()->color('#' . $hexColor);
$this->image->effects()->colorize($color);
}
示例3: 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'];
$position = isset($options['position']) ? $options['position'] : 'center';
switch ($position) {
case 'topleft':
$x = 0;
$y = 0;
break;
case 'top':
$x = ($width - $image->getSize()->getWidth()) / 2;
$y = 0;
break;
case 'topright':
$x = $width - $image->getSize()->getWidth();
$y = 0;
break;
case 'left':
$x = 0;
$y = ($height - $image->getSize()->getHeight()) / 2;
break;
case 'center':
$x = ($width - $image->getSize()->getWidth()) / 2;
$y = ($height - $image->getSize()->getHeight()) / 2;
break;
case 'right':
$x = $width - $image->getSize()->getWidth();
$y = ($height - $image->getSize()->getHeight()) / 2;
break;
case 'bottomleft':
$x = 0;
$y = $height - $image->getSize()->getHeight();
break;
case 'bottom':
$x = ($width - $image->getSize()->getWidth()) / 2;
$y = $height - $image->getSize()->getHeight();
break;
case 'bottomright':
$x = $width - $image->getSize()->getWidth();
$y = $height - $image->getSize()->getHeight();
break;
default:
throw new \InvalidArgumentException("Unexpected position '{$position}'");
break;
}
$size = new Box($width, $height);
$topLeft = new Point($x, $y);
}
$canvas = $this->imagine->create($size, $background);
return $canvas->paste($image, $topLeft);
}
示例4: 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);
}
示例5: 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);
}
示例6: load
public function load(ImageInterface $image, array $options = array())
{
$optionsCount = count($options);
if ($optionsCount < 2) {
throw new InvalidArgumentException('Invalid options for border filter. You must provide array(width, height)');
}
$color = static::DEFAULT_BORDER_COLOR;
if ($optionsCount > 2) {
list($width, $height, $color) = $options;
} else {
list($width, $height) = $options;
}
$border = new Border($image->palette()->color($color), $width, $height);
return $border->apply($image);
}
示例7: drawCenteredText
/**
* Draw centered text in current image
*
* @param string $text
* @param string $color
*
* @return void
*/
protected function drawCenteredText($text, $color)
{
$width = $this->image->getSize()->getWidth();
$height = $this->image->getSize()->getHeight();
$fontColor = $this->image->palette()->color('#' . $color);
$fontSize = 48;
$widthFactor = $width > 160 ? 0.8 : 0.9;
$heightFactor = $height > 160 ? 0.8 : 0.9;
do {
$font = $this->getImagineService()->font(__DIR__ . '/../../../data/font/Roboto-Regular.ttf', $fontSize, $fontColor);
$fontBox = $font->box($text);
$fontSize = round($fontSize * 0.8);
} while ($fontSize > 5 && ($width * $widthFactor < $fontBox->getWidth() || $height * $heightFactor < $fontBox->getHeight()));
$pointX = max(0, floor(($width - $fontBox->getWidth()) / 2));
$pointY = max(0, floor(($height - $fontBox->getHeight()) / 2));
$this->image->draw()->text($text, $font, new Point($pointX, $pointY));
}
示例8: applyEffect
/**
* Применяет эффект к изображению.
* @param ImageInterface $Image
* @param string $effect
* @param string $additional
* @return bool
*/
private function applyEffect(ImageInterface $Image, $effect, $additional = null)
{
switch ($effect) {
case 'resize':
if (!isset($additional['width']) || !isset($additional['height'])) {
return false;
}
$Image->resize(new Box($additional['width'], $additional['height']));
break;
case 'origin':
break;
case 'negative':
$Image->effects()->negative();
break;
case 'grayscale':
$Image->effects()->grayscale();
break;
case 'sharpen':
$Image->effects()->sharpen();
break;
case 'colorize':
$Image->effects()->colorize($Image->palette()->color($additional));
break;
case 'gamma':
$Image->effects()->gamma($additional);
break;
case 'blur':
$Image->effects()->blur($additional);
break;
default:
return false;
}
return true;
}
示例9: resize
/**
* Executes the actual resizing operation on the Imagine image.
* In case of an outbound resize the image will be resized and cropped.
*
* @param ImagineImageInterface $image
* @param string $mode
* @param string $filter
* @return \Imagine\Image\ManipulatorInterface
*/
protected function resize(ImagineImageInterface $image, $mode = ImageInterface::RATIOMODE_INSET, $filter = ImagineImageInterface::FILTER_UNDEFINED)
{
if ($mode !== ImageInterface::RATIOMODE_INSET && $mode !== ImageInterface::RATIOMODE_OUTBOUND) {
throw new \InvalidArgumentException('Invalid mode specified');
}
$imageSize = $image->getSize();
$requestedDimensions = $this->calculateDimensions($imageSize);
$resizedImage = $image->copy();
$resizedImage->usePalette($image->palette());
$resizedImage->strip();
$resizeDimensions = $requestedDimensions;
if ($mode === ImageInterface::RATIOMODE_OUTBOUND) {
$resizeDimensions = $this->calculateOutboundScalingDimensions($imageSize, $requestedDimensions);
}
$resizedImage->resize($resizeDimensions, $filter);
if ($mode === ImageInterface::RATIOMODE_OUTBOUND) {
$resizedImage->crop(new Point(max(0, round(($resizeDimensions->getWidth() - $requestedDimensions->getWidth()) / 2)), max(0, round(($resizeDimensions->getHeight() - $requestedDimensions->getHeight()) / 2))), $requestedDimensions);
}
return $resizedImage;
}
示例10: filterColorize
/**
* Apply colorize filter
*
* @param ImageInterface $image An image instance
* @param string $color The hex value of the color
* @return void
*/
protected function filterColorize(ImageInterface $image, $color)
{
$color = $image->palette()->color($color);
$image->effects()->colorize($color);
return $image;
}
示例11: applyColorizeFilter
/**
* @param \Imagine\Image\ImageInterface $image
* @param array $options
* @return \Imagine\Image\ImageInterface
*/
protected function applyColorizeFilter(ImageInterface $image, $options)
{
if (isset($options['color'])) {
$color = $image->palette()->color($options['color']);
$image->effects()->colorize($color);
}
return $image;
}
示例12: applyEffect
/**
* Применяет эффект к изображению.
* @param ImageInterface $Image
* @param string $effect
* @param string $additional
* @return bool
*/
private function applyEffect(ImageInterface $Image, $effect, $additional = null)
{
switch ($effect) {
case 'origin':
break;
case 'negative':
$Image->effects()->negative();
break;
case 'grayscale':
$Image->effects()->grayscale();
break;
case 'sharpen':
$Image->effects()->sharpen();
break;
case 'colorize':
$Image->effects()->colorize($Image->palette()->color($additional));
break;
case 'gamma':
$Image->effects()->gamma($additional);
break;
case 'blur':
$Image->effects()->blur($additional);
break;
default:
return false;
}
return true;
}
示例13: toRGB
/**
* Ensures that the color mode of the passed image is RGB.
*
* @param ImageInterface $image
*
* @return ImageInterface $image The modified image
*/
private function toRGB(ImageInterface $image)
{
if ($image->palette()->name() == 'cmyk') {
$image->usePalette(new RGB());
}
return $image;
}