Magick++ 6.9.13
Loading...
Searching...
No Matches
button.cpp
1//
2// Magick++ demo to generate a simple text button
3//
4// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2003
5//
6
7#include <Magick++.h>
8#include <cstdlib>
9#include <string>
10#include <iostream>
11
12using namespace std;
13
14using namespace Magick;
15
16int main( int /*argc*/, char ** argv)
17{
18
19 // Initialize ImageMagick install location for Windows
20 InitializeMagick(*argv);
21
22 try {
23
24 string srcdir("");
25 if(getenv("SRCDIR") != 0)
26 srcdir = getenv("SRCDIR");
27
28 //
29 // Options
30 //
31
32 string backGround = "xc:#CCCCCC"; // A solid color
33
34 // Color to use for decorative border
35 Color border = "#D4DCF3";
36
37 // Button size
38 string buttonSize = "120x20";
39
40 // Button background texture
41 string buttonTexture = "granite:";
42
43 // Button text
44 string text = "Button Text";
45
46 // Button text color
47 string textColor = "red";
48
49 // Font point size
50 int fontPointSize = 16;
51
52 //
53 // Magick++ operations
54 //
55
56 Image button;
57
58 // Set button size
59 button.size( buttonSize );
60
61 // Read background image
62 button.read( backGround );
63
64 // Set background to buttonTexture
65 Image backgroundTexture( buttonTexture );
66 button.texture( backgroundTexture );
67
68 // Add some text
69 button.fillColor( textColor );
70 button.fontPointsize( fontPointSize );
71 if (getenv("MAGICK_FONT") != 0)
72 button.font(string(getenv("MAGICK_FONT")));
73 button.annotate( text, CenterGravity );
74
75 // Add a decorative frame
76 button.borderColor( border );
77 button.frame( "6x6+3+3" );
78
79 button.depth( 8 );
80
81 // Quantize to desired colors
82 // button.quantizeTreeDepth(8);
83 button.quantizeDither(false);
84 button.quantizeColors(64);
85 button.quantize();
86
87 // Save to file
88 cout << "Writing to \"button_out.miff\" ..." << endl;
89 button.compressType( RLECompression );
90 button.write("button_out.miff");
91
92 // Display on screen
93 // button.display();
94
95 }
96 catch( exception &error_ )
97 {
98 cout << "Caught exception: " << error_.what() << endl;
99 return 1;
100 }
101
102 return 0;
103}