Permalink
Browse files

Support transparency around clipping paths

This transformation adds support for using a path embedded in the image's
metadata as the clipping path to indicate a transparent area in an image.
  • Loading branch information...
matslindh authored and christeredvartsen committed Sep 22, 2017
1 parent c3ad386 commit f523074df614366507e49a58e360bbbb16f5f2ab
Showing with 39 additions and 0 deletions.
  1. +1 −0 config/config.default.php
  2. +38 −0 src/Image/Transformation/Clip.php
@@ -203,6 +203,7 @@
'blur' => 'Imbo\Image\Transformation\Blur',
'border' => 'Imbo\Image\Transformation\Border',
'canvas' => 'Imbo\Image\Transformation\Canvas',
'clip' => 'Imbo\Image\Transformation\Clip',
'compress' => 'Imbo\Image\Transformation\Compress',
'contrast' => 'Imbo\Image\Transformation\Contrast',
'convert' => 'Imbo\Image\Transformation\Convert',
@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the Imbo package
*
* (c) Christer Edvartsen <cogo@starzinger.net>
*
* For the full copyright and license information, please view the LICENSE file that was
* distributed with this source code.
*/
namespace Imbo\Image\Transformation;
use Imbo\Exception\TransformationException,
ImagickException;
/**
* Clip transformation
*
* @author Mats Lindh <mats@lindh.no>
* @package Image\Transformations
*/
class Clip extends Transformation {
/**
* {@inheritdoc}
*/
public function transform(array $params) {
try {
$this->imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_TRANSPARENT);
$this->imagick->clipImage();
$this->imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_OPAQUE);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
$this->image->hasBeenTransformed(true);
}
}

0 comments on commit f523074

Please sign in to comment.