Image canvas | image | Spatie

 SPATIE

  Image
========

spatie.be/open-source

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

 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)

 Image canvas
============

###  On this page

1. [ Background ](#content-background)
2. [ Border ](#content-border)
3. [ Orientation ](#content-orientation)
4. [ Flip ](#content-flip)

Background
--------------------------------------------------------------------------------------

The `background` method sets the background for transparent images.

The color can be a color name (see [all available color names](https://developer.mozilla.org/en/docs/Web/CSS/color_value#Color_keywords)) or hexadecimal RGB(A).

```
$image->background('darkgray');
```

![Darkgray background on PNG](../images/example-background.png)

Border
--------------------------------------------------------------------------

The `border` method adds border with a certain `$width`, `$borderType` and `$color` to the `Image`.

```
$image->border(15, BorderType::Shrink, '007698');
```

![Border](../images/example-border.jpg)

### Border types

#### `BorderType::Overlay`

By default the border will be added as an overlay to the image.

#### `BorderType::Shrink`

The `Shrink` type shrinks the image to fit the border around. The canvas size stays the same.

#### `BorderType::Expand`

The `Expand` type adds the border to the outside of the image and thus expands the canvas.

Orientation
-----------------------------------------------------------------------------------------

The `orientation` method can be used to rotate the `Image` by passing a Orientation enum value.

```
$image->orientation(Orientation::Rotate180);
```

When passing no parameters the orientation will be derived from the exif data of the image.

```
$image->orientation();
```

![Border](../images/example-orientation.jpg)

The accepted values are:

- `Orientation::Rotate0`
- `Orientation::Rotate90`
- `Orientation::Rotate180`
- `Orientation::Rotate270`

Flip
--------------------------------------------------------------------

Flip/mirror an image 'horizontally', 'vertically' or 'both'.

```
$image->flip(FlipDirection::Horizontal);
```

![Border](../images/example-flip-horizontally.jpg)

The accepted values are:

- `FlipDirection::Vertical`
- `FlipDirection::Horizontal`
- `FlipDirection::Both`
