www/api/Magick++/gravity_8cpp_source.html
| Magick++ 7.1.0 |
gravity.cpp
Go to the documentation of this file.
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 John Christy.
16 //
17
18 #include <Magick++.h>
19 #include <string>
20 #include <iostream>
21 #include <list>
22
23 using namespace std;
24
25 using namespace Magick;
26
27 int main( int /*argc*/, char ** argv)
28 {
29
30// Initialize ImageMagick install location for Windows
31InitializeMagick(*argv);
32
33try {
34
35string srcdir("");
36if(getenv("SRCDIR") != 0)
37 srcdir = getenv("SRCDIR");
38
39int x = 100;
40int y = 100;
41
42 list<Image> animation;
43
44Image base( Geometry(600,600), Color("white") );
45 base.depth(8);
46 base.strokeColor("#600");
48 base.draw( DrawableLine( 300,100, 300,500 ) );
49 base.draw( DrawableLine( 100,300, 500,300 ) );
50 base.draw( DrawableRectangle( 100,100, 500,500 ) );
51 base.density( Point(72,72) );
52 base.strokeColor(Color());
53 base.fillColor("#600");
54 base.fontPointsize( 30 );
55 base.boxColor( "red" );
56 base.animationDelay( 20 );
57 base.compressType( RLECompression );
58
59for ( int angle = 0; angle < 360; angle += 30 )
60 {
61 cout << "angle " << angle << endl;
62Image pic = base;
63 pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
64 pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
65 pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
66 pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
67 pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
68 pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
69 pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
70 pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
71 pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
72 animation.push_back( pic );
73 }
74 cout << "Writing image "gravity_out.miff" ..." << endl;
75writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
76// system( "animate gravity_out.miff" );
77
78 }
79catch( exception &error_ )
80 {
81 cout << "Caught exception: " << error_.what() << endl;
82return 1;
83 }
84
85return 0;
86 }
Definition: Drawable.h:1401
class MagickPPExport Color
Definition: Color.h:18
void annotate(const std::string &text_, const Geometry &location_)
Definition: Image.cpp:1858
void density(const Point &density_)
Definition: Image.cpp:653
STL namespace.
void strokeColor(const Color &strokeColor_)
Definition: Image.cpp:1403
Definition: Drawable.h:1121
void boxColor(const Color &boxColor_)
Definition: Image.cpp:457
void fontPointsize(const double pointSize_)
Definition: Image.cpp:874
class MagickPPExport Geometry
Definition: Geometry.h:21
void writeImages(InputIterator first_, InputIterator last_, const std::string &imageSpec_, bool adjoin_=true)
Definition: STL.h:2823
void fillColor(const Color &fillColor_)
Definition: Image.cpp:786
void draw(const Drawable &drawable_)
Definition: Image.cpp:2798
void animationDelay(const size_t delay_)
Definition: Image.cpp:354
int main(int, char **argv)
Definition: gravity.cpp:27
class MagickPPExport Point
Definition: Geometry.h:200
Definition: Blob.h:17
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45
void depth(const size_t depth_)
Definition: Image.cpp:693
Definition: Image.h:55
void compressType(const CompressionType compressType_)
Definition: Image.cpp:630