Magick++  7.1.2-29
Convert, Edit, Or Compose Bitmap Images
gravity.cpp
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 2000, 2001, 2003
4 //
5 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // Demo of text annotation with gravity. Produces an animation showing
9 // the effect of rotated text assize_t with various gravity specifications.
10 //
11 // After running demo program, run 'animate gravity_out.miff' if you
12 // are using X-Windows to see an animated result.
13 //
14 // Concept and algorithms lifted from PerlMagick demo script written
15 // by Cristy.
16 //
17 
18 #include <Magick++.h>
19 #include <cstdlib>
20 #include <string>
21 #include <iostream>
22 #include <list>
23 
24 using namespace std;
25 
26 using namespace Magick;
27 
28 int main( int /*argc*/, char ** argv)
29 {
30 
31  // Initialize ImageMagick install location for Windows
32  MagickPlusPlusGenesis genesis(*argv);
33 
34  try {
35 
36  string srcdir("");
37  if(getenv("SRCDIR") != 0)
38  srcdir = getenv("SRCDIR");
39  const char *const p = getenv("MAGICK_FONT");
40  const string MAGICK_FONT(p ? p : "");
41 
42 
43  int x = 100;
44  int y = 100;
45 
46  list<Image> animation;
47 
48  Image base( Geometry(600,600), Color("white") );
49  base.depth(8);
50  base.strokeColor("#600");
51  base.fillColor(Color());
52  base.draw( DrawableLine( 300,100, 300,500 ) );
53  base.draw( DrawableLine( 100,300, 500,300 ) );
54  base.draw( DrawableRectangle( 100,100, 500,500 ) );
55  base.density( Point(72,72) );
56  base.strokeColor(Color());
57  base.fillColor("#600");
58  base.fontPointsize( 30 );
59  base.font( MAGICK_FONT );
60  base.boxColor( "red" );
61  base.animationDelay( 20 );
62  base.compressType( RLECompression );
63 
64  for ( int angle = 0; angle < 360; angle += 30 )
65  {
66  cout << "angle " << angle << endl;
67  Image pic = base;
68  pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
69  pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
70  pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
71  pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
72  pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
73  pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
74  pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
75  pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
76  pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
77  animation.push_back( pic );
78  }
79  cout << "Writing image \"gravity_out.miff\" ..." << endl;
80  writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
81  // system( "animate gravity_out.miff" );
82 
83  }
84  catch( exception &error_ )
85  {
86  cout << "Caught exception: " << error_.what() << endl;
87  return 1;
88  }
89 
90  return 0;
91 }