memEx/lib/memex_web/html_helpers.ex

23 lines
607 B
Elixir
Raw Normal View History

2023-04-13 23:29:29 -04:00
defmodule MemexWeb.HTMLHelpers do
2022-02-13 21:56:54 -05:00
@moduledoc """
2023-04-13 23:29:29 -04:00
Contains common helpers that are used for rendering
2022-02-13 21:56:54 -05:00
"""
2023-01-26 00:36:15 -05:00
use Phoenix.Component
2022-02-13 21:56:54 -05:00
2023-01-26 00:46:27 -05:00
@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()
2023-02-14 01:04:15 -05:00
|> EQRCode.png(width: width, background_color: <<24, 24, 27>>, color: <<255, 255, 255>>)
2023-01-26 00:46:27 -05:00
|> Base.encode64()
"data:image/png;base64," <> img_data
end
2022-02-13 21:56:54 -05:00
end