Skip to content

Commit

Permalink
Merge pull request #429 from sgulseth/feature/watermark-opacity
Browse files Browse the repository at this point in the history
Added opacity to watermark image
  • Loading branch information
rexxars committed Jan 13, 2016
2 parents a3a42ca + 7dd99b0 commit 3384ddc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/usage/image-transformations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,14 @@ This transformation can be used to apply a watermark on top of the original imag
``y``
Number of pixels in the Y-axis the watermark image should be offset from the original position (defined by the ``position`` parameter). Supports negative numbers. Defaults to ``0``

``opacity``
Can be an integer between 0 and 100 where 0 is fully transparent, and 100 is fully opaque. Defaults to ``100``

**Examples:**

* ``t[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3f``
* ``t[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3f,width=200,x=5``
* ``t[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3f,height=50,x=-5,y=-5,position=bottom-right``
* ``t[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3f,height=50,x=-5,y=-5,position=bottom-right,opacity=50``

If you want to set the default watermark image you will have to do so in the configuration:

Expand Down
2 changes: 2 additions & 0 deletions library/Imbo/Image/Transformation/Watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function transform(EventInterface $event) {
$position = !empty($params['position']) ? $params['position'] : $this->position;
$x = !empty($params['x']) ? (int) $params['x'] : $this->x;
$y = !empty($params['y']) ? (int) $params['y'] : $this->y;
$opacity = (!empty($params['opacity']) ? (int) $params['opacity'] : 100)/100;

if (empty($imageIdentifier)) {
throw new TransformationException(
Expand All @@ -111,6 +112,7 @@ public function transform(EventInterface $event) {
$watermark = new Imagick();
$watermark->readImageBlob($watermarkData);
$watermarkSize = $watermark->getImageGeometry();
$watermark->setImageOpacity($opacity);
} catch (StorageException $e) {
if ($e->getCode() == 404) {
throw new TransformationException('Watermark image not found', 400);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ public function getParamsForWatermarks() {
'bottom edge of watermark (outside)' => ['x' => 1, 'y' => 101, 'colors' => [255, 255, 255]],
],
],
'opacity' => [
[
'opacity' => 40
],
[
'top left corner' => ['x' => 0, 'y' => 0, 'colors' => [153, 153, 153]], // 255*0.6=153
'top right corner' => ['x' => $this->width - 1, 'y' => 0, 'colors' => [255, 255, 255]],
]
]
];
}

Expand Down

0 comments on commit 3384ddc

Please sign in to comment.