memEx/lib/memex_web/html_helpers.ex
shibao 650d61e95f
All checks were successful
continuous-integration/drone/push Build is passing
fix email comment
2023-04-13 23:48:17 -04:00

23 lines
607 B
Elixir

defmodule MemexWeb.HTMLHelpers do
@moduledoc """
Contains common helpers that are used for rendering
"""
use Phoenix.Component
@doc """
Displays content in a QR code as a base64 encoded PNG
"""
@spec qr_code_image(String.t()) :: String.t()
@spec qr_code_image(String.t(), width :: non_neg_integer()) :: String.t()
def qr_code_image(content, width \\ 384) do
img_data =
content
|> EQRCode.encode()
|> EQRCode.png(width: width, background_color: <<24, 24, 27>>, color: <<255, 255, 255>>)
|> Base.encode64()
"data:image/png;base64," <> img_data
end
end