Adding a watermark | image | Spatie

 SPATIE

  Image
========

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Image](https://spatie.be/docs/image/v3)  Image-manipulations  Adding a watermark

 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/v3/introduction)
- [ Postcardware ](https://spatie.be/docs/image/v3/postcardware)
- [ Installation and setup ](https://spatie.be/docs/image/v3/installation-and-setup)
- [ Supported formats ](https://spatie.be/docs/image/v3/formats)
- [ Questions &amp; issues ](https://spatie.be/docs/image/v3/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/image/v3/changelog)
- [ About us ](https://spatie.be/docs/image/v3/about-us)
- [ Upgrading ](https://spatie.be/docs/image/v3/upgrading)

Usage
-----

- [ Basic usage ](https://spatie.be/docs/image/v3/usage/basic-usage)
- [ Saving images ](https://spatie.be/docs/image/v3/usage/saving-images)
- [ Retrieving properties ](https://spatie.be/docs/image/v3/usage/retrieving-properties)
- [ Colors ](https://spatie.be/docs/image/v3/usage/colors)

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

- [ Overview ](https://spatie.be/docs/image/v3/image-manipulations/overview)
- [ Resizing images ](https://spatie.be/docs/image/v3/image-manipulations/resizing-images)
- [ Optimizing images ](https://spatie.be/docs/image/v3/image-manipulations/optimizing-images)
- [ Adjustments ](https://spatie.be/docs/image/v3/image-manipulations/adjustments)
- [ Image canvas ](https://spatie.be/docs/image/v3/image-manipulations/image-canvas)
- [ Effects ](https://spatie.be/docs/image/v3/image-manipulations/effects)
- [ Adding a watermark ](https://spatie.be/docs/image/v3/image-manipulations/adding-a-watermark)
- [ Adding text ](https://spatie.be/docs/image/v3/image-manipulations/text)

 Adding a watermark
==================

###  On this page

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

Using the `watermark` method you can easily position and add a watermark. By default, it will be placed in the bottom right corner of the image.

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

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

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

The watermark is placed in the bottom right corner by default. You can change this behavior by passing the desired `AlignPosition` Enum:

### Example usage

```
$image->watermark('watermark.png', AlignPosition::center);
```

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

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

Use the `$paddingX` and `$paddingY` params to set the distance from the watermark to the edges of the image. It also accepts a unit param.

By default, the padding values are assumed to be pixels. You can however pass in `Unit:: PERCENT` as the `$paddingUnit` to use percentages as padding values.

### Example usage

```
$image->watermark('watermark.png',
    paddingX: 10,
    paddingY: 10,
    paddingUnit: Unit::Percent
); // 10% padding around the watermark
```

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

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

The width and height of the watermark can be set using the `$width` and `$height` params. You can change the unit of each of them using `$widthUnit` and `$heightUnit`. By default, the values are interpreted in pixels. You can however specify the width or height of the watermark in percentages by setting the `$widthUnit` or `$heightUnit` to `Unit::PERCENT`.

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

```
$image->watermark('watermark.png',
    AlignPosition::Top,
	width: 100,
	widthUnit: Unit::Percent,
	height: 50,
	heightUnit: Unit::Percent
);
```

![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 kept the aspect ratio the same.

### Watermark fit resize

To change the way the watermark is resized within the given boundaries you can use the `$fit` param. This param accepts any `Fit` enum value.

You can read more about resizing using the fit methods in the [resizing images](/docs/image/v3/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',AlignPosition::Top,
	width:100,widthUnit:Unit::Percent,
	height:50,heightUnit:Unit::Percent,
	fit: Fit::Stretch);
```

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

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

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

```
$image->watermark('watermark.png',alpha: 50);
```

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