Class: TinyPNG::Image
- Inherits:
-
Object
- Object
- TinyPNG::Image
- Defined in:
- lib/tinypng/image.rb
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Image
constructor
A new instance of Image.
- #input ⇒ Object
- #output ⇒ Object
- #to_file ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Image
Returns a new instance of Image.
7 8 9 |
# File 'lib/tinypng/image.rb', line 7 def initialize params={} @params = params end |
Instance Method Details
#input ⇒ Object
11 12 13 |
# File 'lib/tinypng/image.rb', line 11 def input @params['input'] end |
#output ⇒ Object
15 16 17 |
# File 'lib/tinypng/image.rb', line 15 def output @params['output'] end |
#to_file ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tinypng/image.rb', line 19 def to_file Tempfile.new(['tinypng', '.png']).tap do |file| begin image_response = TinyPNG::Client.get(output['url']) rescue => e raise Exception.new("Network error: #{e}") end file.write image_response file.rewind end end |