Embed a dynamic Image using Base64
Mix.install([
{:ogi, "~> 0.2.2"},
{:kino, "~> 0.17.0"}
])
Section 1
joke_base64 =
Path.absname(__DIR__)
|> Path.join("joke.jpeg")
|> File.read!()
|> Base.encode64()
# You can embed images as Base64 encoded bytes using the `base64` library.
# As `format`, you can either set a specific format (e.g. `png`) or let Typst
# figure out the file format using `auto`.
markup = """
#set page(width: 800pt, height: 700pt, margin: 64pt)
#import "@preview/based:0.2.0": base64
#place(
right + horizon,
image(base64.decode("#{joke_base64}"), format: "jpg"),
)
"""
{:ok, image} = Ogi.render_to_png("dynamic-image.png", markup, [], [cache_enabled: false])
Kino.render(image)