LoginSignup
17
6

More than 1 year has passed since last update.

QRコード(キューアールコード)は、1994年(平成6年)に自動車部品メーカーであるデンソー(愛知県)の開発部門(現在は分社化してデンソーウェーブ)が発明したマトリックス型二次元コードである。

Toolshed

IExシェルを起動します。

iex

toolshedをインストールします。

Mix.install [{:toolshed, "~> 0.2.0"}]

Toolshed.qr_encode/1を使います。

use Toolshed
qr_encode "elixir-lang.org"

:tada: 以上

Toolshed.qr_encode/1

Toolshed.qr_encode/1QRenco.deというウエブサービスを使ってQRコードを生成しています。

QRenco.de

QRenco.defukuchi/libqrencodeというプログラムを使ってQRコードを生成しています。

Req

QRenco.deはウエブサービスなのでElixirコードから直接使うこともできます。試しにreqというHTTPクライアントを使ってやってみます。

IExシェルを起動します。

iex

reqをインストールします。

Mix.install [{:req, "~> 0.3.0"}]

reqは柔軟性のある構造をしていまして、パイプで繋いで書くこともできますし、関数一個で書くこともできます。

form = [x: "elixir-lang.org"]

Req.new(url: "https://qrenco.de", method: :post)
|> Req.Request.merge_options(form: form)
|> Req.Request.put_header("User-Agent", "curl")
|> Req.Request.run!()
|> then(&IO.puts(&1.body))
form = [x: "elixir-lang.org"]

Req.post!("https://qrenco.de", form: form, headers: [{"User-Agent", "curl"}])
|> then(&IO.puts(&1.body))

他のQRコード関連Elixirパッケージ

順不同

ご参考までに

17
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
6