Class: RubySprites::GraphicsManager::Rmagick

Inherits:
RubySprites::GraphicsManager show all
Defined in:
lib/lash-sprites/graphics_manager/rmagick.rb

Constant Summary collapse

DESCRIPTION =
'RMagick'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.availible?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'lib/lash-sprites/graphics_manager/rmagick.rb', line 9

def self.availible?
  begin
    require 'rubygems'
    require 'RMagick'
  rescue LoadError
    return false
  end
  
  return Magick::Version.match(/^RMagick 2/)
end

Instance Method Details

#combine(images, width, height) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lash-sprites/graphics_manager/rmagick.rb', line 20

def combine(images, width, height)
  image = Magick::Image.new(width, height) { self.background_color = '#0000' }
  images.each do |path, img|
    next unless img.exists?
    i = Magick::Image.read(@sprite.file_root + path).first
    drawer = Magick::Draw.new
    w = width - img.x
    w = img.width if img.width < w
    h = height - img.y
    h = img.height if img.height < h
    drawer.composite(img.x, img.y, w, h, i)
    drawer.draw(image)
    i.destroy!
  end
  image.write(@sprite.image_file)
end

#get_info(path) ⇒ Object



37
38
39
40
41
42
# File 'lib/lash-sprites/graphics_manager/rmagick.rb', line 37

def get_info(path)
  img = Magick::Image.read(@sprite.file_root + path).first
  info = {:width => img.columns, :height => img.rows}
  img.destroy!
  return info
end