Skip to content

Instantly share code, notes, and snippets.

@pasela

pasela/rqrcode_ja.rb

Last active May 22, 2017
Embed
What would you like to do?
[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
You can’t perform that action at this time.