Watermarks | image | Spatie

 SPATIE

  Image
========

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Image](https://spatie.be/docs/image/v2)  Image-manipulations  Watermarks

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/image/v3) [v2](https://spatie.be/docs/image/v2) [v1](https://spatie.be/docs/image/v1)

- [ Introduction ](https://spatie.be/docs/image/v2/introduction)
- [ Postcardware ](https://spatie.be/docs/image/v2/postcardware)
- [ Installation and setup ](https://spatie.be/docs/image/v2/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/image/v2/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/image/v2/changelog)
- [ About us ](https://spatie.be/docs/image/v2/about-us)

Usage
-----

- [ Basic usage ](https://spatie.be/docs/image/v2/usage/basic-usage)
- [ Saving images ](https://spatie.be/docs/image/v2/usage/saving-images)
- [ Retrieving properties ](https://spatie.be/docs/image/v2/usage/retrieving-properties)
- [ Preparing manipulations ](https://spatie.be/docs/image/v2/usage/preparing-manipulations)
- [ Advanced manipulations ](https://spatie.be/docs/image/v2/usage/advanced-manipulations)

Image manipulations
-------------------

- [ Overview ](https://spatie.be/docs/image/v2/image-manipulations/overview)
- [ Resizing images ](https://spatie.be/docs/image/v2/image-manipulations/resizing-images)
- [ Optimizing images ](https://spatie.be/docs/image/v2/image-manipulations/optimizing-images)
- [ Adjustments ](https://spatie.be/docs/image/v2/image-manipulations/adjustments)
- [ Image canvas ](https://spatie.be/docs/image/v2/image-manipulations/image-canvas)
- [ Effects ](https://spatie.be/docs/image/v2/image-manipulations/effects)
- [ Watermarks ](https://spatie.be/docs/image/v2/image-manipulations/watermarks)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/image                                                                                                                                                                                                                                    `

Watermarks
==========

###  On this page

1. [ Watermark opacity ](#content-watermark-opacity)
2. [ Watermark position ](#content-watermark-position)
3. [ Watermark padding ](#content-watermark-padding)
4. [ Watermark size ](#content-watermark-size)

Adding a watermark to an `Image` is really simple:

```
$image->watermark('watermark.png');
```

![Example](../images/example-watermark.jpg)

Watermark opacity
-----------------------------------------------------------------------------------------------------------

Usually watermarks are slightly opaque. You can set the opacity of the watermark with the `watermarkOpacity` method. The accepted value is a percentage between `0` and `100` (default).

Changing the opacity of the watermark requires the `imagick` image driver.

```
$image->watermark('watermark.png')
      ->watermarkOpacity(50);
```

![Example](../images/example-watermark-opacity.jpg)

Watermark position
--------------------------------------------------------------------------------------------------------------

As you can see in the example above the watermark is placed in the bottom right corner by default. This behaviour can be overridden via the `watermarkPosition`. You can use the `POSITION_*` constants on the `Manipulations` class as arguments.

### Example usage

```
$image->watermark('watermark.png')
      ->watermarkPosition(Manipulations::POSITION_CENTER);
```

![Example](../images/example-watermark-position.jpg)

Watermark padding
-----------------------------------------------------------------------------------------------------------

Use the `watermarkPadding` method to set the distance from the watermark to the edges of the image. The method accepts a `$paddingX` value, a `$paddingY` value and an optional `$unit`.

By default the padding values are assumed to be pixels. You can however pass in `Manipulations::UNIT_PERCENT` as the `$unit` to use percentages as padding values.

### Example usage

```
$image->watermark('watermark.png')
      ->watermarkPadding(10, 10, Manipulations::UNIT_PERCENT); // 10% padding around the watermark
```

![Example](../images/example-watermark-padding.jpg)

As a shorthand you can pass in only the `$paddingX` value and it will be used as both the `$paddingX` and `$paddingY` value in pixels:

```
$image->watermark('watermark.png')
      ->watermarkPadding(50); // 50px padding on all edges
```

Watermark size
--------------------------------------------------------------------------------------------------

The width and height of the watermark can be set using the `watermarkWidth` and `watermarkHeight` methods. Both methods take two arguments: an integer `$value` and an optional `$unit`. By default the `$value` is interpreted in pixels. You can however specify the width or height of the watermark in percentages by setting the `$unit` to `Manipulations::UNIT_PERCENT`.

For example you might want to add the watermark on the entire top half of the image:

```
$image->watermark('watermark.png')
      ->watermarkPosition(Manipulations::POSITION_TOP)      // Watermark at the top
      ->watermarkHeight(50, Manipulations::UNIT_PERCENT)    // 50 percent height
      ->watermarkWidth(100, Manipulations::UNIT_PERCENT);   // 100 percent width
```

![Example](../images/example-watermark-resize.jpg)

As you can see in the example above. The watermark automatically resized itself to be contained within the given dimension but also keep the aspect ratio the same.

### Watermark fit resize

To change the way the watermark is resized within the given boundaries you can use the `watermarkFit` method. This method accepts a `$fitMethod` argument. The following `$fitMethods` are available on the `Manipulations` class as constants:

- `Manipulations::FIT_CONTAIN`
- `Manipulations::FIT_MAX`
- `Manipulations::FIT_FILL`
- `Manipulations::FIT_STRETCH`
- `Manipulations::FIT_CROP`

You can read more about resizing using the fit methods in the [resizing images](/image/v1/image-manipulations/resizing-images) part of the docs.

For example you might want to stretch the watermark over the entire bottom half of the image:

```
$image->watermark('watermark.png')
      ->watermarkHeight(50, Manipulations::UNIT_PERCENT)
      ->watermarkWidth(100, Manipulations::UNIT_PERCENT)
      ->watermarkFit(Manipulations::FIT_STRETCH);
```

![Example](../images/example-watermark-resize-stretch.jpg)

*Very pretty.*
