module BarbyTools
Public Class Methods
create_barcode(options)
click to toggle source
生成条码, 不支持utf-8, 比如中文. 支持参数:
content, 要转换的字符串 file_path, 要保存的文件路径(png)
# File lib/eric_tools/barby_tools.rb, line 10 def self.create_barcode options barcode = Barby::Code128B.new(options[:content]) blob = Barby::PngOutputter.new(barcode).to_png(:height => 20, :margin => 5) unless File.exist? options[:file_path] File.open(options[:file_path], 'wb'){|f| f.write blob.force_encoding("ISO-8859-1") #在rails环境中,如果不encode,会报错 } end end
create_qrcode(options)
click to toggle source
生成二维码. 支持中文 支持参数:
content, 要转换的字符串 file_path, 要保存的文件路径(png)
# File lib/eric_tools/barby_tools.rb, line 24 def self.create_qrcode options qrcode = Barby::QrCode.new(options[:content]) blob = Barby::PngOutputter.new(qrcode).to_png(:height => 20, :margin => 5) unless File.exist? options[:file_path] File.open(options[:file_path], 'wb'){|f| f.write blob.force_encoding("ISO-8859-1") } end end