Using Takumi | laravel-og-image | Spatie       

 SPATIE  

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

spatie.be/open-source

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

 Version   v1      

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

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

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

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

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

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

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

###  On this page 

1. [ Installation ](#content-installation)
2. [ Usage ](#content-usage)
3. [ Styles, images, and fonts ](#content-styles-images-and-fonts)
4. [ Limitations and errors ](#content-limitations-and-errors)

[Takumi](https://takumi.kane.tw/) renders HTML and CSS without Chrome or an external rendering service. The optional `TakumiDriver` uses Takumi's command-line application. Browsershot remains the default, and nothing is downloaded automatically.

Takumi is not a browser. It supports a subset of CSS and does not run JavaScript. Try your templates before switching, especially if they depend on Tailwind's browser CDN, JavaScript, or browser-specific layout.

Installation
--------------------------------------------------------------------------------------------

Install Takumi CLI 0.3.1 on every server or queue worker that generates images. You can download a native binary from [Takumi's releases](https://github.com/kane50613/takumi/releases?q=takumi-cli) and put `takumi` on your `PATH`. Native binaries do not need Node.js or Rust at runtime. See the [CLI installation instructions](https://takumi.kane.tw/docs/cli/install) for supported platforms and other installation methods.

If you already use Node.js, you can instead install the CLI in your application's directory:

```
npm install @takumi-rs/cli@0.3.1
```

This npm installation needs Node.js 18+ at runtime. It does not need Chrome. Use `base_path('node_modules/.bin/takumi')` as the binary path in the example below.

Usage
-----------------------------------------------------------------------

Register the driver in your `AppServiceProvider`:

```
use Spatie\OgImage\Drivers\TakumiDriver;
use Spatie\OgImage\Facades\OgImage;

public function boot(): void
{
    OgImage::useDriver(new TakumiDriver(
        binaryPath: '/usr/local/bin/takumi',
        allowedDirectories: [resource_path('og-image')],
        timeout: 60,
    ));
}
```

`binaryPath` defaults to `takumi`, and `timeout` defaults to 60 seconds for each of the preview HTTP request and the render. `allowedDirectories` defaults to an empty array, which allows no local file reads. PHP must be able to start processes.

The driver fetches the `?ogimage` preview URL over HTTP or HTTPS, then sends the HTML to Takumi through standard input. The preview must be reachable from your server and return a successful response without redirecting. Only use trusted application URLs as preview URLs.

The existing image format, quality, dimensions, disk, and caching settings still apply. The default device scale factor of 2 still produces a 2400×1260 image from a 1200×630 template. PNG, JPEG, and WebP are supported.

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

The driver does not download remote assets. Takumi cannot load HTTP or HTTPS stylesheets, images, or fonts, including same-origin URLs generated by `asset()`, `@vite`, or a development server. Instead, embed assets with `data:` URLs or reference local files in an explicitly allowed directory. Use inline CSS or local compiled stylesheets, not a JavaScript-based CSS runtime.

For example, put `card.css`, `brand.woff2`, and `logo.png` in `resources/og-image`. In `card.css`, relative asset paths resolve against the stylesheet:

```
@font-face {
    font-family: Brand;
    src: url('./brand.woff2');
}

body {
    font-family: Brand;
    background: #f5f5f5;
}

.logo {
    width: 120px;
    height: 120px;
    background-image: url('./logo.png');
}
```

To avoid the original page's network-based stylesheets, [publish the screenshot layout](/docs/laravel-og-image/v1/advanced-usage/customizing-the-screenshot-layout) and replace `resources/views/vendor/og-image/screenshot.blade.php` with:

```

<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="file://{{ resource_path('og-image/card.css') }}">
    <style>
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
        html, body { width: {{ $width }}px; height: {{ $height }}px; overflow: hidden; }
    </style>
</head>
<body>{!! $templateContent !!}</body>
</html>
```

This layout deliberately omits `$head`. Keep your `<x-og-image>` markup compatible with these styles. Use absolute `file://` URLs for local assets referenced directly in HTML or inline CSS. Relative HTML paths otherwise resolve against the PHP process's working directory, not the preview URL.

Takumi reads no system fonts. The CLI includes Geist for Latin text. Register other fonts with local `@font-face` rules, including fonts covering any non-Latin characters you use.

Grant only asset directories. Do not allow the application root, `.env` files, private storage, or user-uploaded directories containing files that must not appear in an image. Takumi's sandbox blocks paths and symlinks that escape the allowed directories. Its resource limits also apply.

Limitations and errors
--------------------------------------------------------------------------------------------------------------------------

- Network assets are blocked. The driver uses `--deny-warnings`, so missing or blocked assets, undecodable files, and missing glyphs fail generation rather than silently producing an incomplete image. The exception includes Takumi's diagnostic output.
- JavaScript is never executed. Browser timing options have no equivalent: `waitUntil` is ignored, while `waitForTimeout` and `waitForSelector` are rejected.
- `fullPage`, `selector`, `clip`, and `omitBackground` are not supported by this driver. Set the template's dimensions and background in CSS instead.
- The preview HTTP request does not follow redirects. Use the final URL, including its correct HTTP/HTTPS scheme.
- `?ogimage` still displays HTML in a browser, not Takumi's output. A layout using local `file://` assets will not preview those assets in your browser. Check the generated image when comparing renderers.

Keep Browsershot or Cloudflare for templates that need JavaScript, remote assets, or full browser layout support.

 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)
