-
Notifications
You must be signed in to change notification settings - Fork 2
/
composite_layers.rb.html
80 lines (71 loc) · 2.47 KB
/
composite_layers.rb.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE public PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta name="generator" content="ex2html.rb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/popup.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
hljs.configure({ cssSelector: "pre" });
hljs.highlightAll();
</script>
<title>RMagick example: composite_layers.rb</title>
</head>
<body>
<h1>composite_layers.rb</h1>
<div class="bodybox">
<div class="bodyfloat">
<pre class="language-ruby">
# frozen_string_literal: true
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
</pre>
</div>
</div>
<div id="close"><a href="javascript:window.close();">Close window</a></div>
</body>
</html>