Module: BarbyTools
- Defined in:
- lib/eric_tools/barby_tools.rb
Class Method Summary collapse
-
.create_barcode(options) ⇒ Object
生成条码, 不支持utf-8, 比如中文.
-
.create_qrcode(options) ⇒ Object
生成二维码.
Class Method Details
.create_barcode(options) ⇒ Object
生成条码, 不支持utf-8, 比如中文. 支持参数:
content, 要转换的字符串
file_path, 要保存的文件路径(png)
10 11 12 13 14 15 16 17 18 |
# File 'lib/eric_tools/barby_tools.rb', line 10 def self. = Barby::Code128B.new([:content]) blob = Barby::PngOutputter.new().to_png(:height => 20, :margin => 5) unless File.exist? [:file_path] File.open([:file_path], 'wb'){|f| f.write blob.force_encoding("ISO-8859-1") #在rails环境中,如果不encode,会报错 } end end |
.create_qrcode(options) ⇒ Object
生成二维码. 支持中文支持参数:
content, 要转换的字符串
file_path, 要保存的文件路径(png)
24 25 26 27 28 29 30 31 32 |
# File 'lib/eric_tools/barby_tools.rb', line 24 def self.create_qrcode qrcode = Barby::QrCode.new([:content]) blob = Barby::PngOutputter.new(qrcode).to_png(:height => 20, :margin => 5) unless File.exist? [:file_path] File.open([:file_path], 'wb'){|f| f.write blob.force_encoding("ISO-8859-1") } end end |