Sha256: fc0c85ec5a221be9f56895d98c9c97e894dd04c81b1b6c70239cac87572f2523

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module YAMG
  #
  # SPLASH
  #
  #
  class Splash
    attr_accessor :src, :bg, :size, :icons, :img

    def initialize(src, size, background)
      @src = src
      @size = size
      @bg = background
      @icons = YAMG.load_images(src)
   end

    #
    # Center image
    #
    def splash_center(center)
      icon_size = size.max / 4
      img.resize icon_size if img.dimensions.max >= icon_size
      img.background bg if bg
      img.combine_options do |o|
        o.gravity 'center'
        o.extent size.join('x') # "WxH"
      end
    end

    def compose(other, name)
      img.composite(other) do |o|
        o.compose 'Over'
        o.gravity File.basename(name, '.*')
        o.geometry '+40%+40%'
      end
    end

    #
    # Composite 9 gravity
    #
    def splash_composite(base)
      max = base.dimensions.min / 9
      icons.reduce(base) do |img, over|
        other = MiniMagick::Image.open(File.join(src, over))
        other.resize(max) if other.dimensions.max >= max
        compose(other, over)
      end
      base
    end

    def image
      center = icons.find { |i| i =~ /center/ }
      icons.delete(center)
      self.img = MiniMagick::Image.open(File.join(src, center))

      splash_composite(splash_center(center))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yamg-0.0.9 lib/yamg/splash.rb
yamg-0.0.8 lib/yamg/splash.rb
yamg-0.0.7 lib/yamg/splash.rb