1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 2000, 2001, 2003
5 // Demo of text annotation with gravity. Produces an animation showing
6 // the effect of rotated text assize_t with various gravity specifications.
8 // After running demo program, run 'animate gravity_out.miff' if you
9 // are using X-Windows to see an animated result.
11 // Concept and algorithms lifted from PerlMagick demo script written
22 using namespace Magick;
24 int main( int /*argc*/, char ** argv)
27 // Initialize ImageMagick install location for Windows
28 InitializeMagick(*argv);
33 if(getenv("SRCDIR") != 0)
34 srcdir = getenv("SRCDIR");
39 list<Image> animation;
41 Image base( Geometry(600,600), Color("white") );
43 base.strokeColor("#600");
44 base.fillColor(Color());
45 base.draw( DrawableLine( 300,100, 300,500 ) );
46 base.draw( DrawableLine( 100,300, 500,300 ) );
47 base.draw( DrawableRectangle( 100,100, 500,500 ) );
48 base.density( Point(72,72) );
49 base.strokeColor(Color());
50 base.fillColor("#600");
51 base.fontPointsize( 30 );
52 base.boxColor( "red" );
53 base.animationDelay( 20 );
54 base.compressType( RLECompression );
56 for ( int angle = 0; angle < 360; angle += 30 )
58 cout << "angle " << angle << endl;
60 pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
61 pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
62 pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
63 pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
64 pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
65 pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
66 pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
67 pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
68 pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
69 animation.push_back( pic );
71 cout << "Writing image \"gravity_out.miff\" ..." << endl;
72 writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
73 // system( "animate gravity_out.miff" );
76 catch( exception &error_ )
78 cout << "Caught exception: " << error_.what() << endl;