1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2002, 2003
4 //
5 // GD/PerlMagick example using Magick++ methods.
6 //
7 // Concept and algorithms lifted from PerlMagick demo script
8 //
9
10 #include <Magick++.h>
11 #include <string>
12 #include <iostream>
13
14 using namespace std;
15
16 using namespace Magick;
17
main(int,char ** argv)18 int main( int /*argc*/, char ** argv)
19 {
20
21 // Initialize ImageMagick install location for Windows
22 InitializeMagick(*argv);
23
24 try {
25
26 string srcdir("");
27 if(getenv("SRCDIR") != 0)
28 srcdir = getenv("SRCDIR");
29
30 // Common font to use.
31 string font = "Helvetica";
32 if (getenv("MAGICK_FONT") != 0)
33 font = string(getenv("MAGICK_FONT"));
34
35 //
36 // Create a 300x300 white canvas.
37 //
38 Image image( "300x300", "white" );
39
40 //
41 // Draw texture-filled polygon
42 //
43 // Polygon list
44 std::list<Coordinate> poly_coord;
45 poly_coord.push_back( Coordinate(30,30) );
46 poly_coord.push_back( Coordinate(100,10) );
47 poly_coord.push_back( Coordinate(190,290) );
48 poly_coord.push_back( Coordinate(30,290) );
49
50 Image texture( srcdir + "tile.miff" );
51 image.penTexture( texture );
52 image.draw( DrawablePolygon( poly_coord ) );
53 texture.isValid( false );
54 image.penTexture( texture ); // Unset texture
55
56 //
57 // Draw filled ellipse with black border, and red fill color
58 //
59 image.strokeColor( "black" );
60 image.fillColor( "red" );
61 image.strokeWidth( 5 );
62 image.draw( DrawableEllipse( 100,100, 50,75, 0,360 ) );
63 image.fillColor( Color() ); // Clear out fill color
64
65 //
66 // Draw ellipse, and polygon, with black stroke, strokeWidth of 5
67 //
68 image.strokeColor( "black" );
69 image.strokeWidth( 5 );
70 list<Drawable> drawlist;
71
72 // Add polygon to list
73 poly_coord.clear();
74 poly_coord.push_back( Coordinate(30,30) );
75 poly_coord.push_back( Coordinate(100,10) );
76 poly_coord.push_back( Coordinate(190,290) );
77 poly_coord.push_back( Coordinate(30,290) );
78 drawlist.push_back( DrawablePolygon( poly_coord ) );
79 image.draw( drawlist );
80
81 //
82 // Floodfill object with blue
83 //
84 image.colorFuzz( MaxRGB*0.8 ); // 80%
85 image.floodFillColor( "+132+62", "blue" );
86
87 //
88 // Draw text
89 //
90 image.strokeColor(Color());
91 image.fillColor( "red" );
92 image.font( font );
93 image.fontPointsize( 18 );
94 image.annotate( "Hello world!", "+150+20" );
95
96 image.fillColor( "blue" );
97 image.font( font );
98 image.fontPointsize( 14 );
99 image.annotate( "Goodbye cruel world!", "+150+38" );
100
101 image.fillColor( "black" );
102 image.font( font );
103 image.fontPointsize( 14 );
104 image.annotate( "I'm climbing the wall!", "+280+120",
105 NorthWestGravity, 90.0 );
106 //image.display();
107 //
108 // Write image.
109 //
110
111 cout << "Writing image \"shapes_out.miff\" ..." << endl;
112 image.depth( 8 );
113 image.compressType( RLECompression );
114 image.write( "shapes_out.miff" );
115
116 // cout << "Display image..." << endl;
117 // image.display( );
118
119 }
120 catch( exception &error_ )
121 {
122 cout << "Caught exception: " << error_.what() << endl;
123 return 1;
124 }
125
126 return 0;
127 }
128