Rendering with Takumi | laravel-og-image-rust | Spatie       

 SPATIE  

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-og-image-rust](https://spatie.be/docs/laravel-og-image-rust/v1)  Rendering with Takumi

 Version   v1      

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

  Rendering with Takumi    
- [ Introduction ](https://spatie.be/docs/laravel-og-image-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-og-image-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-og-image-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-og-image-rust/v1/usage)
- [ Rendering with Takumi ](https://spatie.be/docs/laravel-og-image-rust/v1/takumi)
- [ Testing ](https://spatie.be/docs/laravel-og-image-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-og-image-rust/v1/changelog)

 Rendering with Takumi
=====================

###  On this page 

1. [ Installation ](#content-installation)
2. [ Usage ](#content-usage)
3. [ Fonts ](#content-fonts)
4. [ Stylesheets and images ](#content-stylesheets-and-images)
5. [ Limitations ](#content-limitations)

[Takumi](https://takumi.kane.tw) renders HTML and CSS to images inside your application, without Chrome or Cloudflare. It supports a subset of CSS and runs no JavaScript. The browser backends remain available, and Takumi is not compiled unless you enable its feature.

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

Enable the package's `takumi` feature:

```
[dependencies]
spatie-laravel-og-image = { version = "0.1.4", features = ["takumi"] }
```

Building Takumi needs a C compiler. Debug builds render slowly, so optimize Takumi in your application's `Cargo.toml`:

```
[profile.dev.package.takumi-core]
opt-level = 3

[profile.dev.package.takumi-raster]
opt-level = 3

[profile.dev.package.tiny-skia]
opt-level = 3
```

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

Pass a `TakumiCapture` to the service provider instead of a browser capture:

```
use laravel::Application;
use spatie_og_image::{service_provider, Config, TakumiCapture};

let capture = TakumiCapture::new()
    .font(std::fs::read("resources/fonts/inter-latin-400.woff2")?)?
    .allow_origin("https://fonts.bunny.net")?;
let config = Config::new("https://blog.example.test")?;

let application = Application::configure()
    .with_providers(move |providers| {
        providers.add(service_provider(config, capture));
    })
    .create();
```

Everything else works as with the browser backends. Run `og-image:clear` after switching to render cached images again.

The same image options select PNG, JPEG or WebP, dimensions, scale and JPEG/WebP quality. Rendering uses the cached `GenerationMetadata` snapshot, so templates, queues, storage and image routes do not change. Enabling `takumi` adds `Capture` and `Error` variants and makes those enums non-exhaustive; add a wildcard arm to exhaustive matches when opting in. With the feature disabled, the existing API is unchanged.

Fonts
-----------------------------------------------------------------------

Takumi uses no system fonts. Register TTF, OTF, WOFF, or WOFF2 fonts with `font(...)`, or load them with `@font-face`. Registered fonts draw text whose font family is not available, such as `sans-serif`. Characters no font covers, like emoji without an emoji font, are missing from the image.

Stylesheets and images
--------------------------------------------------------------------------------------------------------------------------

Linked stylesheets, fonts and images load from your application's origin. Allow others, such as a CDN or font service, with `allow_origin(...)`. Google Fonts needs `https://fonts.googleapis.com` and `https://fonts.gstatic.com`.

An origin includes its scheme, host and port. Only allow origins you trust; this is not a sandbox for user-supplied HTML or URLs. HTTP(S) URLs with credentials and non-HTTP(S) network resources are rejected. Redirects are never followed, even to another allowed origin. Use the final asset URL instead. Inline `data:` fonts and images are supported; local file URLs are not.

Stylesheets from disallowed origins are skipped with a warning. Images that cannot load fail the capture. Font sources are tried in order; a failed source can fall back to a later one. Each downloaded asset is limited to 16 MiB. The capture waits at most 90 seconds, but CPU work already running on the blocking pool cannot be interrupted when the wait expires.

Link your built CSS: `@import` rules are not loaded, and Vite's development server is another origin.

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

- Takumi supports a subset of CSS. See its [styling reference](https://takumi.kane.tw/docs/styles) for supported properties, selectors and at-rules. Unsupported declarations are ignored.
- JavaScript never runs. Render everything the image shows on the server.
- The `?ogimage` preview renders in your browser, which supports more CSS than Takumi. Check the generated image when you change a template.

 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)
