class YAMG::Splash

SPLASH

Attributes

assets[RW]
bg[RW]
img[RW]
size[RW]
src[RW]

Public Class Methods

new(src, size, background) click to toggle source

Splash

Splash.new(src, size, rounded).image Image class

Icon.new(src, size, rounded).image('.path.ext') Export image

# File lib/yamg/splash.rb, line 18
def initialize(src, size, background)
  @src = src
  @size = size
  @bg = background
  @assets = YAMG.load_images(src)
  YAMG.puts_and_exit("No sources in '#{src}'") if assets.empty?
  %w(bg background wallpaper).each do |i|
    @wallpaper = assets.delete("#{i}.png")
  end
  if (center = assets.delete('center.png'))
    @center =  File.join(src, center)
  end
  @center ||= File.join(File.dirname(__FILE__), 'assets', 'dot.png')
  @img = MiniMagick::Image.open(@center)
end

Public Instance Methods

compose(other, name) click to toggle source
# File lib/yamg/splash.rb, line 47
def compose(other, name)
  img.composite(other) do |o|
    o.gravity File.basename(name, '.*')
    o.compose 'Over'
    padding = name =~ /east|west/ ? '+40%' : '+0%'
    padding += name =~ /north|south/ ? '+40%' : '+0%'
    o.geometry padding
  end
end
image(out = nil) click to toggle source

Outputs instance or writes image to disk

# File lib/yamg/splash.rb, line 72
def image(out = nil)
  splash_start
  splash_composite
  return img unless out
  FileUtils.mkdir_p File.dirname(out)
  img.write(out)
rescue Errno::ENOENT
  YAMG.puts_and_exit("Path not found '#{out}'")
end
splash_composite() click to toggle source

Composite 9 gravity

# File lib/yamg/splash.rb, line 60
def splash_composite
  max = size.min / 9
  assets.each do |over|
    other = MiniMagick::Image.open(File.join(src, over))
    other.resize(max) if other.dimensions.max >= max
    self.img = compose(other, over)
  end
end
splash_start() click to toggle source

Center image

# File lib/yamg/splash.rb, line 37
def splash_start
  icon_size = size.min / 5
  img.resize icon_size if img.dimensions.max >= icon_size
  img.combine_options do |o|
    o.gravity 'center'
    o.background bg if bg
    o.extent size.join('x') # "WxH"
  end
end