Class: YAMG::Splash
- Inherits:
-
Object
- Object
- YAMG::Splash
- Defined in:
- lib/yamg/splash.rb
Overview
SPLASH
Instance Attribute Summary collapse
-
#assets ⇒ Object
Returns the value of attribute assets.
-
#bg ⇒ Object
Returns the value of attribute bg.
-
#img ⇒ Object
Returns the value of attribute img.
-
#size ⇒ Object
Returns the value of attribute size.
-
#src ⇒ Object
Returns the value of attribute src.
Instance Method Summary collapse
- #compose(other, name) ⇒ Object
-
#image(out = nil) ⇒ Object
Outputs instance or writes image to disk.
-
#initialize(src, size, background) ⇒ Splash
constructor
Splash.
-
#splash_composite ⇒ Object
Composite 9 gravity.
-
#splash_start ⇒ Object
Center image.
Constructor Details
#initialize(src, size, background) ⇒ Splash
Splash
Splash.new(src, size, rounded).image Image class
Icon.new(src, size, rounded).image(‘.path.ext’) Export image
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#assets ⇒ Object
Returns the value of attribute assets.
7 8 9 |
# File 'lib/yamg/splash.rb', line 7 def assets @assets end |
#bg ⇒ Object
Returns the value of attribute bg.
7 8 9 |
# File 'lib/yamg/splash.rb', line 7 def bg @bg end |
#img ⇒ Object
Returns the value of attribute img.
7 8 9 |
# File 'lib/yamg/splash.rb', line 7 def img @img end |
#size ⇒ Object
Returns the value of attribute size.
7 8 9 |
# File 'lib/yamg/splash.rb', line 7 def size @size end |
#src ⇒ Object
Returns the value of attribute src.
7 8 9 |
# File 'lib/yamg/splash.rb', line 7 def src @src end |
Instance Method Details
#compose(other, name) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
Outputs instance or writes image to disk
72 73 74 75 76 77 78 79 80 |
# 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 ⇒ Object
Composite 9 gravity
60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
Center image
37 38 39 40 41 42 43 44 45 |
# 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. do |o| o.gravity 'center' o.background bg if bg o.extent size.join('x') # "WxH" end end |