Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 46 lines (35 sloc) 1.222 kB
25bd366 Be helpful: write a descriptive message to stdout when invoked.
rmagick authored
1 # Demonstrate the Draw#rotation= method by producing
2 # an animated MIFF file showing a rotating text string.
3
d9b079a Initial revision
tim authored
4
5 require 'RMagick'
6 include Magick
7
25bd366 Be helpful: write a descriptive message to stdout when invoked.
rmagick authored
8 puts <<END_INFO
9 Demonstrate the rotation= attribute in the Draw class
10 by producing an animated image. View the output image
11 by entering the command: animate rotating_text.miff
12 END_INFO
d9b079a Initial revision
tim authored
13
14 text = Draw.new
15 text.pointsize = 28
16 text.font_weight = BoldWeight
17 text.font_style = ItalicStyle
18 text.gravity = CenterGravity
19
20 # Let's make it interesting. Composite the
21 # rotated text over a gradient fill background.
22 fill = GradientFill.new(100,100,100,100,"yellow","red")
23 bg = Image.new(200, 200, fill)
24
fb84783 Use 'none' for background color
rmagick authored
25 # The "none" color is transparent.
26 fg = Image.new(bg.columns, bg.rows) { self.background_color = "none" }
d9b079a Initial revision
tim authored
27
28 # Here's where we'll collect the individual frames.
29 animation = ImageList.new
30
31 0.step(345,15) { |degrees|
32 frame = fg.copy
33 text.annotate(frame, 0,0,0,0, "Rotating Text") {
34 self.rotation = degrees
35 }
36 # Composite the text over the gradient filled background frame.
37 animation << bg.composite(frame, CenterGravity, DisplaceCompositeOp)
38 }
39
40 animation.delay = 8
41
42 #animation.animate
bb192ae Fix example so it will work "out of the box" on Windows
rmagick authored
43 puts "...Writing rotating_text.gif"
44 animation.write("rotating_text.gif")
d9b079a Initial revision
tim authored
45 exit
Something went wrong with that request. Please try again.