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