Class: Struggle::Tmagick

Inherits:
Object
  • Object
show all
Defined in:
lib/struggle/tmagick.rb

Instance Method Summary collapse

Constructor Details

#initialize(img, newimg = nil) ⇒ Tmagick

Returns a new instance of Tmagick.



3
4
5
6
# File 'lib/struggle/tmagick.rb', line 3

def initialize(img, newimg=nil)
  @pushimg = Magick::Image.read(img).first
  @poppath = newimg.blank? ? img : newimg
end

Instance Method Details

#images(images) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/struggle/tmagick.rb', line 8

def images(images)
  return nil if images.blank?
  images.each do |img|
    image = Magick::Image.read(img[:img]).first.resize_to_fit(img[:w], img[:h])
    @pushimg.composite!(image, img[:x], img[:y], Magick::OverCompositeOp)
  end
  return self
end

#resize(new_width, new_height) ⇒ Object



30
31
32
33
# File 'lib/struggle/tmagick.rb', line 30

def resize(new_width, new_height)
  @pushimg = Magick::Image.read(@pushimg).first.resize_to_fit(new_width, new_height)
  @pushimg.blank? ? nil : self
end

#texts(texts) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/struggle/tmagick.rb', line 17

def texts(texts)
  return nil if texts.blank?
  texts.each do |text|
    copyright = Magick::Draw.new
    copyright.font = text[:font]
    copyright.pointsize = text[:size]
    copyright.font_weight = text[:weight]
    copyright.fill = text[:color]
    copyright.annotate(@pushimg, 0, 0, text[:x], text[:y]+12, text[:text])
  end
  return self
end

#writeObject



35
36
37
# File 'lib/struggle/tmagick.rb', line 35

def write
  @pushimg.write(@poppath)
end