Class: Profound::Image

Inherits:
Object
  • Object
show all
Includes:
Filters::ToyCamera
Defined in:
lib/profound.rb

Instance Method Summary collapse

Methods included from Filters::ToyCamera

#toy_camera

Constructor Details

#initialize(source, caption, options, destination) ⇒ Image

Returns a new instance of Image.



23
24
25
26
27
28
29
30
# File 'lib/profound.rb', line 23

def initialize(source, caption, options, destination)
  @source       = Magick::ImageList.new(source).first
  @target       = Magick::ImageList.new
  @destination  = destination
  @caption      = caption
  @options      = options
  @theme        = Theme.new(options[:theme])
end

Instance Method Details

#_text(stroke_width = 0) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/profound.rb', line 60

def _text(stroke_width = 0)
  image = Magick::Image.new(@source.columns, 100) {
    self.background_color = 'none'
  }
  text = Magick::Draw.new

  color = @theme.color
  text.annotate(image, 0, 0, 0, 0, @caption) {
    self.fill         = color
    self.font_family  = 'Arial'
    self.pointsize    = 80
    self.stroke_width = stroke_width
    self.stroke       = color
    self.gravity      = Magick::CenterGravity
  }

  image
end

#convertObject



32
33
34
35
36
37
# File 'lib/profound.rb', line 32

def convert
  shadow
  text
  filters
  save
end

#filtersObject



43
44
45
46
47
48
# File 'lib/profound.rb', line 43

def filters
  case @options[:filter]
  when :toycamera
    toy_camera
  end
end

#saveObject



56
57
58
# File 'lib/profound.rb', line 56

def save
  @source.write(@destination)
end

#shadowObject



50
51
52
53
54
# File 'lib/profound.rb', line 50

def shadow
  image = _text(40)
  shadow = image.shadow(0, 0, 30).colorize(1, 1, 1, 0, @theme.inverse_color)
  @source = @source.composite(shadow, Magick::CenterGravity, 20, 0, Magick::OverCompositeOp)
end

#textObject



39
40
41
# File 'lib/profound.rb', line 39

def text
  @source = @source.composite(_text, Magick::CenterGravity, Magick::OverCompositeOp)
end