Open Graph and Twitter/X image support for Phoenix controllers.
Add OgEx.Controller to a controller and declare a card for an action:
og_card :show, MyAppWeb.PostOgCardCard-local load/2 retrieves image-specific assigns without running the
normal controller action. Applications can choose signed path or query image
URLs.
Path mode supports either OgEx.Router.og_ex_routes/1 or
plug OgEx, router: MyAppWeb.Router. Choose one, not both. Query mode can be
intercepted by the controller integration without either path integration.
Legacy generated-card and direct-image render(..., og: declaration) calls
remain supported.
See the project README for complete setup, source types, remote-image policy, caching, and current failure behavior.
Summary
Functions
Returns the action that declared the current card.
Dispatches endpoint image requests or preserves legacy query fetching.
Returns the controller that declared the current card.
Builds a lazy font entry for a file below the configured :otp_app.
Returns :open_graph or :twitter for the current image request.
Initializes endpoint image dispatch.
Builds an opaque HEEx source for a private image.
Returns normalized route parameters for the current image request.
Functions
Returns the action that declared the current card.
Dispatches endpoint image requests or preserves legacy query fetching.
With a configured router, candidate path and query image requests are
resolved before Phoenix routing. Without one, this retains the 0.2.x
compatibility behavior.
Returns the controller that declared the current card.
This is available during declaration-based image loading. It returns nil
for ordinary requests and legacy render-time cards.
Builds a lazy font entry for a file below the configured :otp_app.
The marker is resolved when fonts load during a render, so this helper never touches the filesystem:
config :og_ex,
otp_app: :my_app,
fonts: [OgEx.font("priv/fonts/Inter-Regular.ttf")]Relative paths resolve with Application.app_dir/2 at load time; absolute
paths pass through unchanged.
The return value is the plain {:ogex_font, path} tuple. Configuration
evaluated before OgEx is compiled, such as config.exs during dependency
compilation, cannot call this function; use the equivalent literal tuple
there instead.
Returns :open_graph or :twitter for the current image request.
Initializes endpoint image dispatch.
Pass router: MyAppWeb.Router to use endpoint integration. OgEx warns when
that router also contains og_ex_routes().
Builds an opaque HEEx source for a private image.
path is relative to the configured :private_asset_root. Use the return
value as an <img src> inside a generated card:
<img src={OgEx.private_asset("backgrounds/report.png")} />OgEx resolves and verifies the file on the signed image request. The returned string is meaningful only to OgEx's resource loader; it is not a public URL.
Returns normalized route parameters for the current image request.