class Mumble::ImgReader

Constants

FORMATS

Public Class Methods

msg_from_file(file) click to toggle source
# File lib/mumble-ruby2/img_reader.rb, line 20
def msg_from_file(file)
  @@file = file
  @@ext = File.extname(@@file)[1..-1]
  validate_file

  data = File.read @@file
  "<img src='data:image/#{@@ext};base64,#{Base64.encode64(data)}'/>"
end

Private Class Methods

validate_file() click to toggle source
# File lib/mumble-ruby2/img_reader.rb, line 30
def validate_file
  raise LoadError.new("#{@@file} not found") unless File.exists? @@file
  raise UnsupportedImgFormat unless FORMATS.include? @@ext
  raise ImgTooLarge unless File.size(@@file) <= 128 * 1024
end