File: composite_layers.rb

package info (click to toggle)
ruby-rmagick 6.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,232 kB
  • sloc: cpp: 19,563; ruby: 17,147; sh: 88; javascript: 36; makefile: 13
file content (53 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'rmagick'

module Magick
  class ImageList
    # Create a shadow image for each image in the list
    def shadow(x_offset = 4, y_offset = 4, sigma = 4.0, opacity = 1.0)
      map { |frame| frame.shadow(x_offset, y_offset, sigma, opacity) }
    end
  end
end

ruby = Magick::ImageList.new

# Draw a rotating "Ruby" animation
gc = Magick::Draw.new
gc.gravity = Magick::CenterGravity
gc.pointsize = 24
gc.font_weight = Magick::BoldWeight
gc.fill = 'darkred'
gc.stroke = 'black'
gc.stroke_width = 1

23.times do
  ruby << Magick::Image.new(100, 100) { |info| info.background_color = 'none' }
  gc.annotate(ruby, 0, 0, 0, 0, 'Ruby')
  gc.rotation = 15
end

# Create a gradient background
bg = Magick::ImageList.new
bg.new_image(99, 99, Magick::GradientFill.new(50, 50, 50, 50, 'white', 'tan'))
bg.border!(1, 1, 'black')

# Create the animated shadows of the rotating "Ruby" animation
shadows = ruby.shadow(2, 5, 3)

# Composite the shadow animation over the background. Since there is only one
# background image, it will replicated for each frame in the shadow animation.
begin
  result = bg.composite_layers(shadows)

  # Composite the "Ruby" animation over the previous composite
  result = result.composite_layers(ruby)
  result.delay = 10
  result.write('composite_layers.gif')
  result[0].write('composite_layers1.gif')
rescue NotImplementedError
  result = Magick::Image.read('images/notimplemented.gif').first
  result.resize!(100, 100)
  result.write('composite_layers.gif')
  result.write('composite_layers1.gif')
end
exit