Last active
May 22, 2017 07:20
-
-
Save pasela/8114904 to your computer and use it in GitHub Desktop.
[ruby] rQRCode Japanese string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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