Created
March 13, 2017 09:55
-
-
Save Eric-Guo/0665862c2b2369d72fcad81a9ae6bfdb to your computer and use it in GitHub Desktop.
QR Code (二维码)个人名片产生器
This file contains 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
#!/usr/bin/ruby | |
#Developed by proxhotdog on 15 June 2012 | |
#Ruby 1.8.7 | |
#Mac OSX 10.7 Lion | |
#QR code generator written in ruby | |
require 'rubygems' | |
require 'rqrcode_png' | |
firstname = "Chan" #姓 | |
lastname = "Tai Man" #名 | |
name = "N:#{lastname};#{firstname}"+"\n" | |
phone = "TEL:+86XXXXXXXXXXX"+"\n" #电话号码 | |
company = "ORG:The ABC Computer Company"+"\n"#机构或公司名 | |
email = "EMAIL:ruby_is_good@gmail.com"+"\n"#电邮 | |
qqnum = "X-QQ:1234567890"+"\n"#QQ号 | |
if (qqnum.size <=6) #检查qq号是否空白,如果空白就直接跳过vcard打包过程 | |
qqnum = "" | |
end | |
vcard = "BEGIN:VCARD\n#{name}#{phone}#{company}#{email}#{qqnum}END:VCARD" #打包成vcard格式 | |
puts "="*50 | |
puts vcard | |
puts "="*50 | |
puts "Char count: #{vcard.size}" #显示资讯总长度 | |
if (vcard.size <= 25) #根据资讯长度决定QR Code大小 | |
size = 1 | |
elsif (vcard.size <= 47) | |
size = 2 | |
elsif (vcard.size <= 77) | |
size = 3 | |
elsif (vcard.size <= 114) | |
size = 4 | |
elsif (vcard.size <= 619) | |
size = 13 | |
elsif (vcard.size <= 2677) | |
size = 31 | |
end | |
puts "size: #{size}" | |
level = 'h' #容错程度 ('l','m','h','q') | |
qr = RQRCode::QRCode.new(vcard, :size => size, :level => level) | |
png = qr.to_img | |
png.resize(320, 320).save("#{Dir.pwd}/#{lastname}_qrcode.png") #输出成图片,以名字去命名图片 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment