-
Notifications
You must be signed in to change notification settings - Fork 2
/
drop_shadow.rb.html
86 lines (70 loc) · 2.37 KB
/
drop_shadow.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
81
82
83
84
85
86
<!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: drop_shadow.rb</title>
</head>
<body>
<h1>drop_shadow.rb</h1>
<div class="bodybox">
<div class="bodyfloat">
<pre class="language-ruby">
# frozen_string_literal: true
require 'rmagick'
# Add a drop shadow to a text string. This example
# uses a 3-image animation to show each step of the
# process
ROWS = 60
COLS = 250
TEXT = 'Ruby rocks!'
# This imagelist will contain the animation frames
anim = Magick::ImageList.new
ex = Magick::Image.new(COLS, ROWS)
# Create a Draw object to draw the text with. Most of the text
# attributes are shared between the shadow and the foreground.
text = Magick::Draw.new
text.gravity = Magick::CenterGravity
text.pointsize = 36
text.font_weight = Magick::BoldWeight
text.font_style = Magick::ItalicStyle
text.stroke = 'transparent'
# Draw the shadow text first. The color is a very light gray.
# Position the text to the right and down.
text.annotate(ex, 0, 0, 2, 2, TEXT) do |options|
options.fill = 'gray60'
end
# Save the first frame of the animation.
anim << ex.copy
# Blur the shadow. Save a copy of the image as the 2nd frame.
ex = ex.blur_image(0, 3)
anim << ex.copy
# Add the foreground text in solid black. Position it
# to the left and up from the shadow text.
text.annotate(ex, 0, 0, -1, -1, TEXT) do |options|
options.fill = 'maroon'
end
# Save yet another copy of the image as the 3rd frame.
anim << ex.copy
# Set the delay between frames to 1 second.
anim.delay = 100
# Set the delay after the last frame to 3 seconds.
anim.cur_image.delay = 300
# Iterate forever.
anim.iterations = 0
# anim.animate
anim.write('drop_shadow.gif')
exit
</pre>
</div>
</div>
<div id="close"><a href="javascript:window.close();">Close window</a></div>
</body>
</html>