Class: Cowsapi::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/cowsapi/app.rb

Instance Method Summary collapse

Instance Method Details

#convert(string, params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cowsapi/app.rb', line 36

def convert (string, params)
  format = params[:format]
  if format
    if %w'jpg gif png'.include?(format)
      content_type "image/#{format}"
      f = Tempfile.new('cow')
      begin
        f.write(string)
        f.rewind
        `convert -font Courier #{dimensions(params)} label:@#{f.path} #{format}:-`
      ensure
        f.close
        f.unlink
      end
    end
  else
    string
  end
end

#dimensions(params) ⇒ Object



56
57
58
59
60
# File 'lib/cowsapi/app.rb', line 56

def dimensions(params)
  x = params[:x].nil? ? 320 : params[:x]
  y = params[:y].nil? ? 240 : params[:y]
  "-size #{x}x#{y}"
end