Skip to content

Instantly share code, notes, and snippets.

@pasela
Last active May 22, 2017 07:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasela/8114904 to your computer and use it in GitHub Desktop.
Save pasela/8114904 to your computer and use it in GitHub Desktop.
[ruby] rQRCode Japanese string
# encoding: utf-8
require 'rqrcode'
require 'rqrcode_png'
str = '日本語てすと'
# QRコードで日本語を扱う場合はShift_JISが一般的
# 加えてライブラリの問題なのかASCII-8BITで渡さないとうまくいかない
qr_str = str.encode('CP932')
qr_str.force_encoding('ASCII-8BIT')
qrcode = RQRCode::QRCode.new(qr_str, :size => 4, :level => :h)
qr_png = qrcode.to_img
qr_png.save('test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment