Using Takumi | laravel-og-image-go | Spatie       

 SPATIE  

  Laravel Open Graph Image Go 
==============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-og-image-go](https://spatie.be/docs/laravel-og-image-go/v1)  Advanced-usage  Using Takumi

 Version   v1      

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

  Using Takumi    
- [ 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)
- [ Using Takumi ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-takumi)
- [ 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)

 Using Takumi
============

###  On this page 

1. [ Installing Takumi ](#content-installing-takumi)
2. [ Configuring the driver ](#content-configuring-the-driver)
3. [ Styles, images and fonts ](#content-styles-images-and-fonts)
4. [ Limitations ](#content-limitations)

If you don't want to install Chrome on your server or use Cloudflare, you can use [Takumi](https://takumi.kane.tw) instead. It renders HTML and CSS with a native layout engine. Browsershot remains the default driver.

Installing Takumi
-----------------------------------------------------------------------------------------------------------

Install the Takumi CLI on the server that generates your images. This driver is tested with Takumi 0.3.1. With [cargo-binstall](https://github.com/cargo-bins/cargo-binstall), you can install a prebuilt binary:

```
cargo binstall takumi-cli --version 0.3.1
takumi --version
```

You can also build it with `cargo install --locked takumi-cli --version 0.3.1`. See [Takumi's installation instructions](https://takumi.kane.tw/docs/cli/install) for supported platforms and npm installation. A native binary does not need Node.js, Puppeteer or Chrome at runtime.

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

```
ogimage.New(func(c *ogimage.Config) {
    c.Driver = ogimage.TakumiDriver{
        BinaryPath: "/usr/local/bin/takumi",
        Fonts: []string{"/srv/app/og-assets/fonts/Inter-Regular.ttf"},
        AssetDirectories: []string{"/srv/app/og-assets"},
    }
})
```

`BinaryPath` defaults to `takumi` on `PATH`. If you set it, use an absolute path to the native executable. An npm installation includes a native executable inside its platform-specific `@takumi-rs/cli-*` package. Point to that executable rather than its Node launcher, so cancellation stops the renderer itself. Windows executables have an `.exe` extension.

The driver fetches your page's `?ogimage` preview and passes the HTML to Takumi in a private temporary directory. Preview redirects and non-successful HTTP responses fail generation. Only pass trusted application URLs. The initial preview request can reach private networks, just like the browser drivers.

Your existing templates, dimensions, scale, formats, storage and image caching still work. PNG, JPEG, JPG and WebP are supported. `Quality` applies to JPEG and WebP. Zero keeps Takumi's default, which is JPEG quality 75 and lossless WebP. PNG ignores quality. The default 2× scale produces 2400×1260 pixels from a 1200×630 template.

Styles, images and fonts
------------------------------------------------------------------------------------------------------------------------------

Takumi does not fetch network resources. The driver does not download or rewrite linked stylesheets, images or fonts, including resources on your application's own origin. Inline the CSS your card needs and embed images as `data:` URLs, or use local files in explicitly allowed directories.

For example, a dedicated screenshot layout can reference these local assets:

```
<link rel="stylesheet" href="file:///srv/app/og-assets/card.css">
<img src="file:///srv/app/og-assets/logo.png" width="160" height="80" alt="Spatie">
```

Set `AssetDirectories` to allow only the directories containing those files. The HTML preview is a temporary file, so relative HTML URLs do not resolve against your website or application directory. Use absolute `file:` URLs. Relative references inside local CSS, such as `url(logo.png)` or `@import 'fonts.css'`, resolve against that stylesheet.

Every allowed directory and its children become readable by the document. Never allow the application root, a home directory, or a directory containing secrets. References outside the allowed directories, including symlink escapes, fail generation. Without `AssetDirectories`, the document has access only to its private temporary directory.

Register trusted local font files with `Fonts`. Takumi uses their internal family names in CSS, not their filenames. Registering a font does not grant access to the directory containing it. You can also use local `@font-face` rules inside an allowed directory. Takumi does not read installed system fonts. Its built-in Geist fallback covers Latin, so supply fonts for other scripts.

The normal preview includes your page's original `<head>`. A remote stylesheet or font link there will fail Takumi generation. Use a [custom screenshot layout](customizing-the-screenshot-layout) or the `Actions.RenderScreenshot` callback to supply an asset-safe head. The driver enables Takumi's `--deny-warnings`, so blocked network resources, missing files and other renderer warnings fail instead of producing an incomplete image.

Limitations
-----------------------------------------------------------------------------------------

- Takumi supports only part of HTML and CSS. Check its [supported styles](https://takumi.kane.tw/docs/styles) and test your actual card. A preview in Chrome is not a Takumi preview, and output can differ from a browser screenshot.
- JavaScript does not run. Client-side rendering, scripts that load assets, and animations cannot prepare the card. Render the content on the server.
- Network images, stylesheets, CSS imports and web fonts are not loaded, even from the same origin. Supply inline content, data URLs or explicitly allowed local assets.
- Browser `WaitUntil` and `Delay` options are rejected. Takumi does not wait for page events or execute scripts.
- A capture has a 30-second deadline, including the preview request. A shorter caller deadline or cancellation is also respected. Preview HTML is limited to 8 MiB.
- Takumi limits raster output to 64 megapixels. Its CLI also limits each resource to 32 MiB, all resources to 256 MiB, resource count to 1024 and nested CSS imports to 16 levels.

Switch back to Browsershot or Cloudflare when a card needs browser CSS or JavaScript.

 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)
