Customizing screenshots | 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)  Basic-usage  Customizing screenshots

 Version   v1      

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

  Customizing screenshots    
- [ 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)

 Customizing screenshots
=======================

###  On this page 

1. [ Size ](#content-size)
2. [ Format ](#content-format)
3. [ Quality ](#content-quality)
4. [ Disk ](#content-disk)
5. [ Cloudflare ](#content-cloudflare)
6. [ Configuring the screenshot ](#content-configuring-the-screenshot)

Customize screenshots in the callback passed to `ogimage.New`.

Size
--------------------------------------------------------------------

Images default to 1200×630 CSS pixels at 2× scale, producing 2400×1260 pixels:

```
ogimage.New(func(c *ogimage.Config) {
    c.Width = 1200
    c.Height = 630
})
```

Override both dimensions per template:

```
<template data-og-image data-og-width="800" data-og-height="400">
    <h1>{{.Title}}</h1>
</template>
```

Per-template dimensions take priority and are included in the content hash. Both must be present and positive. Dimensions are limited to 8192 CSS pixels per side.

Format
--------------------------------------------------------------------------

Set `c.Format = "webp"` to change the default. Supported formats are `jpeg`, `jpg`, `png`, and `webp`. Templates may use `data-og-format` to override it.

Quality
-----------------------------------------------------------------------------

Set `c.Quality = 80` for JPEG or WebP. Zero uses the driver's default quality. PNG ignores quality.

Disk
--------------------------------------------------------------------

Set `c.Disk = "s3"` and `c.Path = "og-images"` to change storage. The disk must exist in your Laravel configuration.

Cloudflare
--------------------------------------------------------------------------------------

Set `c.Driver = ogimage.CloudflareDriver{APIToken: token, AccountID: account}`. See [installation and setup](../installation-setup).

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

The callback runs after the URL, dimensions, format, quality, and default scale are resolved. It applies to the built-in and custom drivers:

```
c.ConfigureScreenshot = func(s *ogimage.Screenshot) {
    s.Scale = 1
    s.WaitUntil = "networkidle0"
    s.Delay = 300 * time.Millisecond
}
```

`WaitUntil` supports `load`, `domcontentloaded`, `networkidle0`, and `networkidle2` with the default browser driver. Keep the format consistent with the requested filename. For browser-specific options such as Chrome's path, configure the Browsershot driver directly.

 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)
