Module: PictureHandler::Uploader::ImgVersion::ClassMethods

Defined in:
lib/picture_handler/uploader/img_version.rb

Instance Method Summary collapse

Instance Method Details

#quality(image, value) ⇒ Object



70
71
72
# File 'lib/picture_handler/uploader/img_version.rb', line 70

def quality(image, value)
  image.quality(value)
end

#resize_to_fill(image, value) ⇒ Object

————————————————————– # ————- Method accepted into a version —————- # ————————————————————– #



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/picture_handler/uploader/img_version.rb', line 41

def resize_to_fill(image, value)
  width = value.first
  height = value.last
  gravity = 'Center'
  raise PictureHandler::Exceptions::WrongArgument.new(key),
        "You need to specify a width and height as argument of 'resize_to_fill' method." if width.blank? || height.blank?

  cols, rows = image[:dimensions]
  image.combine_options do |cmd|
    if width != cols || height != rows
      scale_x = width/cols.to_f
      scale_y = height/rows.to_f
      if scale_x >= scale_y
        cols = (scale_x * (cols + 0.5)).round
        rows = (scale_x * (rows + 0.5)).round
        cmd.resize "#{cols}"
      else
        cols = (scale_y * (cols + 0.5)).round
        rows = (scale_y * (rows + 0.5)).round
        cmd.resize "x#{rows}"
      end
    end
    cmd.gravity gravity
    cmd.background "rgba(255,255,255,0.0)"
    cmd.extent "#{width}x#{height}" if cols != width || rows != height
  end
  # image = yield(image) if block_given?
end