Module: SpriteFactory::Library::ImageMagick

Defined in:
lib/sprite_factory/library/image_magick.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VALID_EXTENSIONS =
[:png, :jpg, :jpeg, :gif, :ico]

Class Method Summary collapse

Class Method Details

.create(filename, images, width, height) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sprite_factory/library/image_magick.rb', line 36

def self.create(filename, images, width, height)
  # we want to invoke:
  # convert -size #{width}x#{height} xc:none
  #   #{input} -geometry +#{x}+#{y} -composite
  # #{output}
  
  args = ["-size", "#{width}x#{height}", "xc:none"]
  images.each do |image|
    args +=  [image[:path], "-geometry", "+#{image[:x]}+#{image[:y]}", "-composite"]
  end
  args << filename
  
  run("convert", args)
  true
end

.load(files) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sprite_factory/library/image_magick.rb', line 21

def self.load(files)
  files.map do |filename|
    path = "#{filename}[0]"   # layer 0
    output = run("identify", ['-format', '%wx%h', path])
    
    width, height = output.chomp.split(/x/).map(&:to_i)
    {
      :filename => filename,
      :path     => path,
      :width    => width,
      :height   => height
    }
  end
end