Class: Cowsapi::App

Inherits:
Padrino::Application
  • Object
show all
Defined in:
app/app.rb

Instance Method Summary collapse

Instance Method Details

#convert(string, params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/app.rb', line 21

def convert (string, params)
  case content_type
  when *[:jpg, :gif, :png]
    f = Tempfile.new('cow')
    begin
      f.write(string)
      f.rewind
      `convert -font Courier #{dimensions} label:@#{f.path} #{content_type}:-`
    ensure
      f.close
      f.unlink
    end
  when :html
    <<-eos
<html>
  <body>
    <img style="padding-left:30px" src="#{request.scheme}://#{request.host}/#{params[:name]}/#{params[:say]}.png" />
  </body>
</html>
    eos
  else 
    string
  end
end

#dimensionsObject



46
47
48
49
50
# File 'app/app.rb', line 46

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