Image canvas | image-go | Spatie       

 SPATIE  

image-go
========

spatie.be/open-source

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

 Version   v1      

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

  Image canvas    
- [ Introduction ](https://spatie.be/docs/image-go/v1/introduction)
- [ Postcardware ](https://spatie.be/docs/image-go/v1/postcardware)
- [ Installation and setup ](https://spatie.be/docs/image-go/v1/installation-and-setup)
- [ Supported formats ](https://spatie.be/docs/image-go/v1/formats)
- [ Questions &amp; issues ](https://spatie.be/docs/image-go/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/image-go/v1/changelog)
- [ About us ](https://spatie.be/docs/image-go/v1/about-us)
- [ Upgrading ](https://spatie.be/docs/image-go/v1/upgrading)
- [ Testing ](https://spatie.be/docs/image-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/image-go/v1/releasing)

Usage
-----

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

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

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

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

###  On this page 

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

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

The `Background` method sets the background for transparent images and future canvas growth. It flattens existing transparency against the chosen color:

```
photo.Background("darkgray")
```

The color can be a name or hexadecimal RGB(A). New images can use `"none"` for a transparent canvas. The default canvas fill and JPEG flattening color is white.

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

The `Border` method adds a border with a width, type and color:

```
photo.Border(15, image.BorderShrink, "007698")
```

### Border types

#### `image.BorderOverlay`

Paints over the image edges without changing dimensions.

#### `image.BorderShrink`

Shrinks the image to fit a uniform border around it. The canvas size stays the same. This may alter the inner image's aspect ratio, unlike PHP's aspect-preserving shrink implementation. A border leaving no image pixels returns an error.

#### `image.BorderExpand`

Adds the border outside the image, expanding each dimension by twice the border width.

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

The `Orientation` method rotates clockwise by `0`, `90`, `180`, `270` or `-90` degrees:

```
photo.Orientation(180)
```

Passing no angle applies EXIF orientation. `Load` and `FromBytes` already normalize all eight EXIF transforms, so calling this again does not rotate the image twice.

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

Flip or mirror an image horizontally, vertically or both:

```
photo.Flip(image.Horizontal)
photo.Flip(image.Vertical)
photo.Flip(image.Both)
```

Resizing the canvas
-----------------------------------------------------------------------------------------------------------------

Change the canvas without scaling the image. The position anchors the existing content:

```
photo.ResizeCanvas(500, 300, image.Center, false)
photo.ResizeCanvas(-20, 40, image.TopLeft, true)
```

Relative dimensions add to the current size and may be negative. Absolute zero dimensions keep the original dimension. The resulting dimensions must be positive.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
