Magick++ 7.1.1
Loading...
Searching...
No Matches
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 <string>
20#include <iostream>
21#include <list>
22
23using namespace std;
24
25using namespace Magick;
26
27int main( int /*argc*/, char ** argv)
28{
29
30 // Initialize ImageMagick install location for Windows
31 InitializeMagick(*argv);
32
33 try {
34
35 string srcdir("");
36 if(getenv("SRCDIR") != 0)
37 srcdir = getenv("SRCDIR");
38 const char *const p = getenv("MAGICK_FONT");
39 const string MAGICK_FONT(p ? p : "");
40
41
42 int x = 100;
43 int y = 100;
44
45 list<Image> animation;
46
47 Image base( Geometry(600,600), Color("white") );
48 base.depth(8);
49 base.strokeColor("#600");
50 base.fillColor(Color());
51 base.draw( DrawableLine( 300,100, 300,500 ) );
52 base.draw( DrawableLine( 100,300, 500,300 ) );
53 base.draw( DrawableRectangle( 100,100, 500,500 ) );
54 base.density( Point(72,72) );
55 base.strokeColor(Color());
56 base.fillColor("#600");
57 base.fontPointsize( 30 );
58 base.font( MAGICK_FONT );
59 base.boxColor( "red" );
60 base.animationDelay( 20 );
61 base.compressType( RLECompression );
62
63 for ( int angle = 0; angle < 360; angle += 30 )
64 {
65 cout << "angle " << angle << endl;
66 Image pic = base;
67 pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
68 pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
69 pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
70 pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
71 pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
72 pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
73 pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
74 pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
75 pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
76 animation.push_back( pic );
77 }
78 cout << "Writing image \"gravity_out.miff\" ..." << endl;
79 writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
80 // system( "animate gravity_out.miff" );
81
82 }
83 catch( exception &error_ )
84 {
85 cout << "Caught exception: " << error_.what() << endl;
86 return 1;
87 }
88
89 return 0;
90}