Installation &amp; setup | laravel-og-image-go | Spatie       

 SPATIE  

laravel-og-image-go
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-og-image-go](https://spatie.be/docs/laravel-og-image-go/v1)  Installation &amp; setup

 Version   v1      

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

  Installation &amp; setup    
- [ Introduction ](https://spatie.be/docs/laravel-og-image-go/v1/introduction)
- [ Requirements ](https://spatie.be/docs/laravel-og-image-go/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-og-image-go/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-og-image-go/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/laravel-og-image-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-og-image-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-og-image-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-og-image-go/v1/support-us)
- [ About us ](https://spatie.be/docs/laravel-og-image-go/v1/about-us)

Basic usage
-----------

- [ How it works ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/how-it-works)
- [ Getting started ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/getting-started)
- [ Customizing screenshots ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/customizing-screenshots)
- [ Defining fallback images ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/defining-fallback-images)
- [ Caching and storage ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/managing-caching-and-storage)
- [ Pre-generating images ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/pre-generating-images)
- [ Clearing generated images ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/clearing-generated-images)

Advanced usage
--------------

- [ Customizing the page URL ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/customizing-the-page-url)
- [ Using a custom screenshot driver ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-a-custom-screenshot-driver)
- [ Customizing the screenshot layout ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/customizing-the-screenshot-layout)
- [ Customizing actions ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/customizing-actions)
- [ Troubleshooting ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/troubleshooting)
- [ Using a hosted solution ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-a-hosted-solution)
- [ Using Laravel Boost ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-laravel-boost)

 Installation &amp; setup
========================

###  On this page 

1. [ Configuring the screenshot driver ](#content-configuring-the-screenshot-driver)
2. [ Configuring the package ](#content-configuring-the-package)

You can install the package with Go modules:

```
go get github.com/spatie/laravel-og-image-go@v0.1.0
```

Register it explicitly in `bootstrap/app.go`:

```
import (
    ogimage "github.com/spatie/laravel-og-image-go"
    laravel "go.laravel.com"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{ogimage.New()},
    }
}
```

The package adds middleware to the `web` group automatically. It handles meta tags, fallback images, and preview rendering. The `/og-image/{filename}` endpoint is a bare route without sessions or CSRF middleware. Do not add the page middleware to the image endpoint.

Configuring the screenshot driver
-----------------------------------------------------------------------------------------------------------------------------------------------------------

### Browsershot (default)

Install Node.js, Puppeteer and Chrome/Chromium as described in [Browsershot Go](https://github.com/spatie/browsershot-go). The default driver needs no additional configuration when these are available.

For browser-specific options, configure a fresh Browsershot builder for each capture:

```
import "github.com/spatie/browsershot-go"

ogimage.New(func(c *ogimage.Config) {
    c.Driver = ogimage.BrowsershotDriver{
        Configure: func(b *browsershot.Browsershot) {
            b.SetChromePath("/usr/bin/chromium").WaitUntilNetworkIdle()
        },
    }
})
```

The callback runs after the shared screenshot options. It can set the Node binary, Puppeteer module path, browser arguments, readiness checks, timeout, runner, or image transform. Do not retain and reuse the mutable builder across captures. Only use `NoSandbox()` in an environment that provides the required isolation.

### Cloudflare

If you don't want to install a browser on your server, use Cloudflare's Browser Rendering API:

```
ogimage.New(func(c *ogimage.Config) {
    c.Driver = ogimage.CloudflareDriver{
        APIToken: os.Getenv("CLOUDFLARE_API_TOKEN"),
        AccountID: os.Getenv("CLOUDFLARE_ACCOUNT_ID"),
    }
})
```

Store credentials in your deployment environment, not source code. The token must have permission to call Browser Rendering for the configured account.

Configuring the package
-----------------------------------------------------------------------------------------------------------------------------

Pass configuration callbacks to `New`. They run after environment defaults and before validation. No config file publishing or package discovery is needed in a compiled Go application.

SettingEnvironmentDefault`BaseURL`Laravel's `APP_URL`Application URL`Disk``OG_IMAGE_DISK``public``Path``OG_IMAGE_PATH``og-images``Width``OG_IMAGE_WIDTH``1200``Height``OG_IMAGE_HEIGHT``630``Format``OG_IMAGE_FORMAT``jpeg``Quality``OG_IMAGE_QUALITY``0`, driver's default`PreviewParameter``OG_IMAGE_PREVIEW_PARAMETER``ogimage``MaxAge``OG_IMAGE_MAX_AGE`, seconds`24 * time.Hour``MetadataTTL``OG_IMAGE_METADATA_TTL`, seconds`30 * 24 * time.Hour``LockTimeout``OG_IMAGE_LOCK_TIMEOUT`, seconds`time.Minute`Invalid environment values stop startup. Code callbacks cannot hide malformed typed environment values. Set `RemoteDisk` when a custom disk should redirect to its public URL. Laravel's S3 and Cloud disks are detected automatically.

`Driver`, `ConfigureScreenshot`, `Fallback`, `ResolveURL`, and the three `Actions` callbacks are explicit customization points. Each application receives a new service, even when reusing a package registration across tests. Callbacks and custom drivers must support concurrent requests.

 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)
