LoginSignup
3
0

More than 3 years have passed since last update.

【Ruby】rqr_codeでundefined method `dark?'が発生する

Posted at

課題

既存の記事を参考にrqr_codeを利用したら undefined method `dark?' が出た。

再現手順

rqr_codeのインストール
$ gem install rqrcode_png
基本コードの丸写し
require 'rqrcode'
require 'rqrcode_png'
require 'chunky_png'

qr = RQRCode::QRCode.new( "Hello World!!", size: 3, level: :h)
img = qr.to_img

img.resize(200, 200).save("hello_world.png")
実行エラー
$ ruby qr_code.rb 
Traceback (most recent call last):
<中略>
rqrcode_png/sequence.rb:11:in `block (2 levels) in dark_squares_only': undefined method `dark?' for #<RQRCode::QRCode:0x00007f9126021200> (NoMethodError)

結論

.to_imgでは無く.as_pngで回避できた。

.to_imgを.as_pngに変更
require 'rqrcode'
require 'rqrcode_png'
require 'chunky_png'

qr = RQRCode::QRCode.new( "Hello World!!", size: 3, level: :h)
# img = qr.to_img
img = qr.as_png

img.resize(200, 200).save("hello_world.png")

参考情報

[Ruby]QRコードの生成、埋め込み
https://qiita.com/koteko/items/d6d033997c544c47b718

Rubyで簡単にQRコード画像を生成する方法
https://qiita.com/sakaitaka/items/c753103c93fa177e4466

rqrcode
https://github.com/whomwah/rqrcode

3
0
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
3
0