Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

BlueHash

livebooks/vix/blurhash.livemd

BlueHash

Mix.install([
  {:image, "~> 0.54"},
  {:kino, "~> 0.14"}
])

画像の読込

{puppies_img, _} =
  "/home/livebook/vix/puppies.png"
  |> Image.open!()
  |> Image.split_alpha()

puppies_img

BlurHash の文字列取得

{:ok, blurhash} = Image.Blurhash.encode(puppies_img)

BlurHash の画像取得

{:ok, decoded} = Image.Blurhash.decode(blurhash, 400, 400)

[
  puppies_img,
  decoded
]
|> Kino.Layout.grid(columns: 2)

ぼかし具合の制御

9..2//-1
|> Enum.map(fn components ->
  puppies_img
  |> Image.Blurhash.encode(x_components: components, y_components: components)
  |> elem(1)
  |> Image.Blurhash.decode(400, 400)
  |> elem(1)
end)
|> then(&[puppies_img | &1])
|> Kino.Layout.grid(columns: 3)