/
rotating_text.rb
executable file
·48 lines (38 loc) · 1.37 KB
/
rotating_text.rb
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
# Demonstrate the Draw#rotation= method by producing
# an animated MIFF file showing a rotating text string.
require 'RMagick'
include Magick
puts <<END_INFO
Demonstrate the rotation= attribute in the Draw class
by producing an animated image. View the output image
by entering the command: animate rotating_text.miff
END_INFO
text = Draw.new
text.pointsize = 28
text.font_weight = BoldWeight
text.font_style = ItalicStyle
text.gravity = CenterGravity
# Let's make it interesting. Composite the
# rotated text over a gradient fill background.
fill = GradientFill.new(100,100,100,100,"yellow","red")
bg = Image.new(200, 200, fill)
# Since antialiasing text on a transparent background doesn't
# look good, write the text on an opaque yellow background.
fg = Image.new(bg.columns, bg.rows) { self.background_color = "yellow" }
# Here's where we'll collect the individual frames.
animation = ImageList.new
0.step(345,15) { |degrees|
frame = fg.copy
text.annotate(frame, 0,0,0,0, "Rotating Text") {
self.rotation = degrees
}
# Composite the text over the gradient filled background frame.
animation << bg.composite(frame, CenterGravity, DisplaceCompositeOp)
}
animation.delay = 8
# ignored if ImageMagick not configured with ZLIB
animation.compression = ZipCompression
#animation.animate
puts "...Writing rotating_text.miff"
animation.write("rotating_text.miff")
exit