class Udongo::ImageManipulation::ResizeAndPad
Public Instance Methods
resize(path)
click to toggle source
Resize the image to fit within the specified dimensions while retaining the original aspect ratio. If necessary, will pad the remaining area with the given color, which defaults to transparent (for gif and png, white for jpeg).
Possible values for options are: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
# File lib/udongo/image_manipulation/resize_and_pad.rb, line 16 def resize(path) gravity = @options.key?(:gravity) ? @options[:gravity] : 'Center' background = @options.key?(:background) ? @options[:background] : :transparant img = MiniMagick::Image.open(@file) img.combine_options do |cmd| cmd.thumbnail "#{@width}x#{@height}>" if background.to_sym == :transparent cmd.background 'rgba(255, 255, 255, 0.0)' else cmd.background background end cmd.gravity gravity cmd.extent "#{@width}x#{@height}" end img.write(path) end