本文整理汇总了PHP中Imbo\EventManager\EventInterface::getArgument方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::getArgument方法的具体用法?PHP EventInterface::getArgument怎么用?PHP EventInterface::getArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imbo\EventManager\EventInterface
的用法示例。
在下文中一共展示了EventInterface::getArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$params = $event->getArgument('params');
$maxWidth = !empty($params['width']) ? (int) $params['width'] : 0;
$maxHeight = !empty($params['height']) ? (int) $params['height'] : 0;
try {
$sourceWidth = $image->getWidth();
$sourceHeight = $image->getHeight();
$width = $maxWidth ?: $sourceWidth;
$height = $maxHeight ?: $sourceHeight;
// Figure out original ratio
$ratio = $sourceWidth / $sourceHeight;
// Is the original image larger than the max-parameters?
if ($sourceWidth > $width || $sourceHeight > $height) {
if ($width / $height > $ratio) {
$width = round($height * $ratio);
} else {
$height = round($width / $ratio);
}
} else {
// Original image is smaller than the max-parameters, don't transform
return;
}
$this->imagick->setOption('jpeg:size', $width . 'x' . $height);
$this->imagick->thumbnailImage($width, $height);
$size = $this->imagick->getImageGeometry();
$image->setWidth($size['width'])->setHeight($size['height'])->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例2: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$params = $event->getArgument('params');
$color = !empty($params['color']) ? $this->formatColor($params['color']) : $this->color;
$width = isset($params['width']) ? (int) $params['width'] : $this->width;
$height = isset($params['height']) ? (int) $params['height'] : $this->height;
$mode = !empty($params['mode']) ? $params['mode'] : $this->mode;
try {
if ($mode === 'outbound') {
// Paint the border outside of the image, increasing the width/height
if ($this->imagick->getImageAlphaChannel() !== 0) {
// If we have an alpha channel and call `borderImage()`, Imagick will remove
// the alpha channel - if we have an alpha channel, use an alternative approach
$this->expandImage($color, $width, $height, $image);
} else {
// If we don't have an alpha channel, use the more cost-efficient `borderImage()`
$this->imagick->borderImage($color, $width, $height);
}
} else {
// Paint the border inside of the image, keeping the orignal width/height
$this->drawBorderInside($color, $width, $height, $image);
}
$size = $this->imagick->getImageGeometry();
$image->setWidth($size['width'])->setHeight($size['height'])->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
} catch (ImagickPixelException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例3: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$params = $event->getArgument('params');
if (empty($params['width']) && empty($params['height'])) {
throw new TransformationException('Missing both width and height. You need to specify at least one of them', 400);
}
$width = !empty($params['width']) ? (int) $params['width'] : 0;
$height = !empty($params['height']) ? (int) $params['height'] : 0;
$originalWidth = $image->getWidth();
$originalHeight = $image->getHeight();
if ($width === $originalWidth && $height === $originalHeight) {
// Resize params match the current image size, no need for any resizing
return;
}
// Calculate width or height if not both have been specified
if (!$height) {
$height = $originalHeight / $originalWidth * $width;
} else {
if (!$width) {
$width = $originalWidth / $originalHeight * $height;
}
}
try {
$this->imagick->setOption('jpeg:size', $width . 'x' . $height);
$this->imagick->thumbnailImage($width, $height);
$size = $this->imagick->getImageGeometry();
$image->setWidth($size['width'])->setHeight($size['height'])->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例4: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$params = $event->getArgument('params');
$threshold = !empty($params['threshold']) ? (double) $params['threshold'] : $this->threshold;
try {
$this->imagick->sepiaToneImage($threshold);
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例5: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$params = $event->getArgument('params');
$brightness = isset($params['b']) ? (int) $params['b'] : 100;
$saturation = isset($params['s']) ? (int) $params['s'] : 100;
$hue = isset($params['h']) ? (int) $params['h'] : 100;
try {
$this->imagick->modulateImage($brightness, $saturation, $hue);
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例6: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$params = $event->getArgument('params');
$preset = isset($params['preset']) ? $params['preset'] : null;
switch ($preset) {
case 'moderate':
$radius = 2;
$sigma = 1;
$gain = 2;
$threshold = 0.05;
break;
case 'strong':
$radius = 2;
$sigma = 1;
$gain = 3;
$threshold = 0.025;
break;
case 'extreme':
$radius = 2;
$sigma = 1;
$gain = 4;
$threshold = 0;
break;
case 'light':
default:
// Default values (with only adding ?t[]=sharpen)
$radius = 2;
$sigma = 1;
$gain = 1;
$threshold = 0.05;
}
if (isset($params['radius'])) {
$radius = (double) $params['radius'];
}
if (isset($params['sigma'])) {
$sigma = (double) $params['sigma'];
}
if (isset($params['gain'])) {
$gain = (double) $params['gain'];
}
if (isset($params['threshold'])) {
$threshold = (double) $params['threshold'];
}
try {
$this->imagick->unsharpMaskImage($radius, $sigma, $gain, $threshold);
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例7: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$pois = $this->getPoisFromMetadata($event, $image);
if (empty($pois) || !is_array($pois)) {
return;
}
$params = $event->getArgument('params');
$color = !empty($params['color']) ? $this->formatColor($params['color']) : $this->color;
$borderSize = isset($params['borderSize']) ? (int) $params['borderSize'] : $this->borderSize;
$pointSize = isset($params['pointSize']) ? (int) $params['pointSize'] : $this->pointSize;
$imageWidth = $image->getWidth();
$imageHeight = $image->getHeight();
try {
foreach ($pois as $poi) {
if (isset($poi['width']) && isset($poi['height'])) {
$this->drawPoiRectangle($poi, $color, $borderSize - 1, $imageWidth, $imageHeight);
} else {
if (isset($poi['cx']) && isset($poi['cy'])) {
$this->drawPoiCircle($poi, $color, $borderSize, $pointSize);
} else {
throw new TransformationException('Point of interest had neither `width` and `height` nor `cx` and `cy`');
}
}
}
$image->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例8: transform
/**
* {@inheritdoc}
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
try {
// Contrast
$this->imagick->contrastImage(1);
// Noise
$this->imagick->addNoiseImage(Imagick::NOISE_GAUSSIAN, Imagick::CHANNEL_GREEN);
// Desaturate + adjust brightness
$this->imagick->modulateImage(135, 25, 100);
// Adjust color balance
$this->imagick->evaluateImage(Imagick::EVALUATE_MULTIPLY, 1.1, Imagick::CHANNEL_RED);
$this->imagick->evaluateImage(Imagick::EVALUATE_MULTIPLY, 1.02, Imagick::CHANNEL_BLUE);
$this->imagick->evaluateImage(Imagick::EVALUATE_MULTIPLY, 1.1, Imagick::CHANNEL_GREEN);
// Gamma
$this->imagick->gammaImage(0.87);
// Vignette
$width = $image->getWidth();
$height = $image->getHeight();
$size = $height > $width ? $width / 6 : $height / 6;
$this->imagick->setImageBackgroundColor(new ImagickPixel('black'));
$this->imagick->vignetteImage(0, 60, 0 - $size, 0 - $size);
// Mark as transformed
$image->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例9: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$params = $event->getArgument('params');
foreach (['width', 'height'] as $param) {
if (!isset($params[$param])) {
throw new TransformationException('Missing required parameter: ' . $param, 400);
}
}
// Fetch the x, y, width and height of the resulting image
$x = !empty($params['x']) ? (int) $params['x'] : $this->x;
$y = !empty($params['y']) ? (int) $params['y'] : $this->y;
$mode = !empty($params['mode']) ? $params['mode'] : null;
$width = (int) $params['width'];
$height = (int) $params['height'];
$imageWidth = $image->getWidth();
$imageHeight = $image->getHeight();
// Set correct x and/or y values based on the crop mode
if ($mode === 'center' || $mode === 'center-x') {
$x = (int) ($imageWidth - $width) / 2;
}
if ($mode === 'center' || $mode === 'center-y') {
$y = (int) ($imageHeight - $height) / 2;
}
// Throw exception on X/Y values that are out of bounds
if ($x + $width > $imageWidth) {
throw new TransformationException('Crop area is out of bounds (`x` + `width` > image width)', 400);
} else {
if ($y + $height > $imageHeight) {
throw new TransformationException('Crop area is out of bounds (`y` + `height` > image height)', 400);
}
}
// Return if there is no need for cropping
if ($x === 0 && $y === 0 && $imageWidth <= $width && $imageHeight <= $height) {
return;
}
try {
$this->imagick->cropImage($width, $height, $x, $y);
$this->imagick->setImagePage(0, 0, 0, 0);
$size = $this->imagick->getImageGeometry();
$image->setWidth($size['width'])->setHeight($size['height'])->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例10: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
try {
$this->imagick->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例11: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$params = $event->getArgument('params');
$alpha = isset($params['sharpen']) ? (double) $params['sharpen'] : 1;
$alpha = isset($params['alpha']) ? (double) $params['alpha'] : $alpha;
$beta = isset($params['beta']) ? (double) $params['beta'] : 0.5;
$sharpen = $alpha > 0;
if ($alpha == 0) {
return;
}
$beta *= $this->getQuantumRange();
try {
$this->imagick->sigmoidalContrastImage($sharpen, abs($alpha), $beta);
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例12: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
try {
$this->imagick->transverseImage();
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例13: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$params = $event->getArgument('params');
if (empty($params['angle'])) {
throw new TransformationException('Missing required parameter: angle', 400);
}
$angle = (int) $params['angle'];
$bg = !empty($params['bg']) ? $this->formatColor($params['bg']) : $this->bg;
try {
$this->imagick->rotateImage($bg, $angle);
$size = $this->imagick->getImageGeometry();
$image->setWidth($size['width'])->setHeight($size['height'])->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
} catch (ImagickPixelException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例14: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$params = $event->getArgument('params');
$sharpen = isset($params['sharpen']) ? (int) $params['sharpen'] : 0;
try {
if ($sharpen > 0) {
for ($i = 0; $i < $sharpen; $i++) {
$this->imagick->contrastImage(1);
}
} else {
for ($i = 0; $i >= $sharpen; $i--) {
$this->imagick->contrastImage(0);
}
}
$event->getArgument('image')->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
示例15: transform
/**
* Transform the image
*
* @param EventInterface $event The event instance
*/
public function transform(EventInterface $event)
{
$params = $event->getArgument('params');
if (empty($params['level'])) {
throw new TransformationException('Missing required parameter: level', 400);
}
$this->level = (int) $params['level'];
if ($this->level < 0 || $this->level > 100) {
throw new TransformationException('level must be between 0 and 100', 400);
}
}