Class: Udongo::ImageManipulation::ResizeToLimit

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/udongo/image_manipulation/resize_to_limit.rb

Instance Method Summary collapse

Methods included from Base

#initialize

Instance Method Details

#resize(path) ⇒ Object

Resize the image to fit within the specified dimensions while retaining the original aspect ratio. Will only resize the image if it is larger than the specified dimensions. The resulting image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.



13
14
15
16
17
18
19
20
21
# File 'lib/udongo/image_manipulation/resize_to_limit.rb', line 13

def resize(path)
  img = MiniMagick::Image.open(@file)
  img.combine_options do |c|
    c.quality @options[:quality] if @options[:quality]
    c.resize "#{@width}x#{@height}>"
  end

  img.write(path)
end