Magick++ 7.1.1
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// Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
7// dedicated to making software imaging solutions freely available.
8//
9
10#include <Magick++.h>
11#include <string>
12#include <iostream>
13
14using namespace std;
15
16using namespace Magick;
17
18int 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 //
31 // Options
32 //
33
34 string backGround = "xc:#CCCCCC"; // A solid color
35
36 // Color to use for decorative border
37 Color border = "#D4DCF3";
38
39 // Button size
40 string buttonSize = "120x20";
41
42 // Button background texture
43 string buttonTexture = "granite:";
44
45 // Button text
46 string text = "Button Text";
47
48 // Button text color
49 string textColor = "red";
50
51#if defined(MAGICKCORE_FREETYPE_DELEGATE)
52 // Font point size
53 int fontPointSize = 16;
54#endif
55
56 //
57 // Magick++ operations
58 //
59
60 Image button;
61
62 // Set button size
63 button.size( buttonSize );
64
65 // Read background image
66 button.read( backGround );
67
68 // Set background to buttonTexture
69 Image backgroundTexture( buttonTexture );
70 button.texture( backgroundTexture );
71
72#if defined(MAGICKCORE_FREETYPE_DELEGATE)
73 // Add some text
74 button.fillColor( textColor );
75 button.fontPointsize( fontPointSize );
76 if (getenv("MAGICK_FONT") != 0)
77 button.font(string(getenv("MAGICK_FONT")));
78 button.annotate( text, CenterGravity );
79#endif
80
81 // Add a decorative frame
82 button.borderColor( border );
83 button.frame( "6x6+3+3" );
84
85 button.depth( 8 );
86
87 // Quantize to desired colors
88 // button.quantizeTreeDepth(8);
89 button.quantizeDither(false);
90 button.quantizeColors(64);
91 button.quantize();
92
93 // Save to file
94 cout << "Writing to \"button_out.miff\" ..." << endl;
95 button.compressType( RLECompression );
96 button.write("button_out.miff");
97
98 // Display on screen
99 // button.display();
100
101 }
102 catch( exception &error_ )
103 {
104 cout << "Caught exception: " << error_.what() << endl;
105 return 1;
106 }
107
108 return 0;
109}