Installation | laravel-og-image-rust | Spatie       

 SPATIE  

laravel-og-image-rust
=====================

spatie.be/open-source

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

 Version   v1      

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

  Installation    
- [ 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)
- [ Testing ](https://spatie.be/docs/laravel-og-image-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-og-image-rust/v1/changelog)

 Installation
============

###  On this page 

1. [ Environment ](#content-environment)
2. [ Queue and cache ](#content-queue-and-cache)

- Use Rust 1.99+, `laravel-rust =0.1.0`, and the framework's Tokio runtime.
- Install Chrome for local capture. Remote CDP and Cloudflare capture do not need a local browser.

Use a neighboring checkout, or pin the Git repository to an immutable revision:

```
[dependencies]
spatie-laravel-og-image = { path = "../laravel-og-image-rust" }
laravel = { package = "laravel-rust", version = "=0.1.0", default-features = false }
```

Install the native provider once during application setup:

```
use laravel::{Application, config::Env};
use spatie_og_image::{service_provider, BrowsershotCapture, Config};

let mut config = Config::new("https://blog.example.test")?;
config.fallback_url = Some("https://blog.example.test/assets/default-card.jpg".parse()?);

let application = Application::configure()
    .replace_env(Env::default())
    .with_providers(move |providers| {
        providers.add(service_provider(config, BrowsershotCapture::new()));
    })
    .create();
```

- The provider registers namespaced `og-image` views, `og-image:clear`, `og-image:generate`, a lazy `OgImage` singleton validated at boot, and `/og-image/{filename}`.
- The default disk/path are `public` / `og-images`. Configure disks using the application's native filesystem configuration.
- Change typed config in `.with_config(...)` using `config.section_mut::<spatie_og_image::Config>()`. Provider defaults run first.
- Bind a customized `OgImage` in `.with_services(...)` to override the provider's singleton.
- Set `register_routes = false` for application-owned route grouping or authentication, then call `service.routes(router)`. Keep image routes outside response-rewriting middleware.
- Add `.middleware(RenderOgImage)` to HTML page routes. It rewrites successful UTF-8 HTML responses with a known body size up to 8 MiB.
- Middleware skips JSON, redirects, streams and encoded responses. It drops stale length and validator headers after rewriting and uses `Config::base_url`, never the incoming Host header.
- Alternatively, call `prepare` explicitly for successful HTML page responses.

Environment
-----------------------------------------------------------------------------------------

The provider reads these optional environment variables through the framework's `Env`. Invalid typed values stop application startup rather than silently selecting defaults:

- `OG_IMAGE_DISK`, `OG_IMAGE_PATH`, `OG_IMAGE_ROUTE_PREFIX`, `OG_IMAGE_ROUTES`.
- `OG_IMAGE_PREVIEW_PARAMETER`.
- `OG_IMAGE_WIDTH`, `OG_IMAGE_HEIGHT`, `OG_IMAGE_SCALE`, `OG_IMAGE_FORMAT`, `OG_IMAGE_QUALITY`.
- `OG_IMAGE_MAX_AGE`, `OG_IMAGE_METADATA_TTL`, `OG_IMAGE_LOCK_TIMEOUT`, all in seconds.
- `OG_IMAGE_QUEUE_CONNECTION`, `OG_IMAGE_QUEUE`.
- Set the public origin, fallback URL and optional shared limiter in the typed `Config` passed to the provider.
- Read capture credentials through the application's `Env` or secret store, then pass the configured backend to the provider. Do not commit tokens.

Queue and cache
-----------------------------------------------------------------------------------------------------

- Run an asynchronous queue connection and a worker consuming `og-images`. The `sync` connection blocks the image request during capture; `discard` drops the job. Neither is suitable for production generation.
- Use a persistent cache shared by web processes and workers, supporting atomic locks, `add`, and compare-and-swap. Memory cache is for single-process tests.
- Metadata and pending-job uniqueness default to one day. Jobs retry for up to one day, with three ordinary errors and backoffs of 60 seconds, 10 minutes, and one hour. Set `metadata_ttl` to at least one day with the supplied jobs.
- Keep `lock_timeout` longer than your job/capture timeout. It defaults to three minutes; the supplied job times out after two minutes. Lock contention releases the queued job for five seconds instead of blocking a worker.
- A crashed worker's pending lock expires with the configured metadata lifetime.
- To share a Cloudflare quota, use the same cache backend, cache prefix, limiter key, and limit across applications. Each application must use the same account for that key.

 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)
