Class: Minimage::Processor::MiniMagick

Inherits:
Base
  • Object
show all
Defined in:
lib/minimage/processor/mini_magick.rb

Instance Attribute Summary

Attributes inherited from Base

#stream

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Minimage::Processor::Base

Instance Method Details

#fill(width, height, gravity = :center) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/minimage/processor/mini_magick.rb', line 24

def fill(width, height, gravity = :center)
  manipulate! do |img|
    if width && height
      width   = width.to_i
      height  = height.to_i
      gravity = :center unless gravity
      gravity = gravity.to_s.capitalize.gsub(/(?:_)([a-z\d]*)/i) { $1.capitalize }
      cols, rows = img[:dimensions]
      img.combine_options do |c|
        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
            c.resize "#{cols}"
          else
            cols = (scale_y * (cols + 0.5)).round
            rows = (scale_y * (rows + 0.5)).round
            c.resize "x#{rows}"
          end
        end
        c.gravity gravity
        c.background "rgba(255,255,255,0.0)"
        c.extent "#{width}x#{height}" if cols != width || rows != height
      end
    else
      img.resize "#{width}" if width
      img.resize "x#{height}" if height
    end
    img
  end
end

#fit(width, height = nil, gravity = nil) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/minimage/processor/mini_magick.rb', line 58

def fit(width, height = nil, gravity = nil)
  manipulate! do |img|
    img.resize "#{width}x#{height}" if width && height
    img.resize "#{width}" if width
    img.resize "x#{height}" if height
    img
  end
end

#format(format) ⇒ Object



8
9
10
11
12
13
# File 'lib/minimage/processor/mini_magick.rb', line 8

def format(format)
  manipulate! do |img|
    img.format format.to_s.downcase
    img
  end
end

#limit(width, height = nil, gravity = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/minimage/processor/mini_magick.rb', line 15

def limit(width, height = nil, gravity = nil)
  manipulate! do |img|
    img.resize "#{width}x#{height}>" if width && height
    img.resize "#{width}" if width
    img.resize "x#{height}" if height
    img
  end
end

#scale(width, height = nil, gravity = nil) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/minimage/processor/mini_magick.rb', line 67

def scale(width, height = nil, gravity = nil)
  manipulate! do |img|
    img.resize "#{width}x#{height}!" if width && height
    img.resize "#{width}" if width
    img.resize "x#{height}" if height
    img
  end
end