2022-07-25 19:31:54 -04:00
|
|
|
defmodule MemexWeb.ViewHelpers do
|
2022-02-13 21:56:54 -05:00
|
|
|
@moduledoc """
|
|
|
|
Contains common helpers that can be used in liveviews and regular views. These
|
2022-07-25 19:31:54 -04:00
|
|
|
are automatically imported into any Phoenix View using `use MemexWeb,
|
2022-02-25 21:53:04 -05:00
|
|
|
:view`
|
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
|