class Dmmyix::Image
Public Class Methods
new(params)
click to toggle source
# File lib/dmmyix/image.rb, line 5 def initialize(params) @params = params @image = MiniMagick::Image.open(image_path) end
Public Instance Methods
convert()
click to toggle source
# File lib/dmmyix/image.rb, line 10 def convert @image.combine_options do |b| b.gravity(image_gravity) if @params[:fit] == "crop" resize_params = if resized_image_height < image_height "x#{image_height}" else "#{image_width}x" end b.resize(resize_params) b.extent("#{image_width}x#{image_height}") else b.resize("#{image_width}x#{image_height}") end b.blur("0x#{image_blur}") b.strip end @image.format("jpg") @image.write("/tmp/#{@image.signature}.jpg") @image end
Private Instance Methods
image_blur()
click to toggle source
# File lib/dmmyix/image.rb, line 65 def image_blur (@params[:blur].presence || 0).to_i / 10 end
image_gravity()
click to toggle source
# File lib/dmmyix/image.rb, line 54 def image_gravity case @params[:crop] when "top" then "North" when "bottom" then "South" when "left" then "West" when "right" then "East" else "Center" end end
image_height()
click to toggle source
# File lib/dmmyix/image.rb, line 46 def image_height (@params[:h].presence || @image.height).to_i end
image_path()
click to toggle source
# File lib/dmmyix/image.rb, line 36 def image_path path = "public/#{@params[:path]}" return path if @params[:format].blank? "#{path}.#{@params[:format]}" end
image_width()
click to toggle source
# File lib/dmmyix/image.rb, line 42 def image_width (@params[:w].presence || @image.width).to_i end
resized_image_height()
click to toggle source
# File lib/dmmyix/image.rb, line 50 def resized_image_height (@image.height * image_width) / @image.width end