Magick++  7.0.10
detrans.cpp
Go to the documentation of this file.
1 //
2 // Replace transparency in an image with a solid color using Magick++
3 //
4 // Useful to see how a transparent image looks on a particular
5 // background color, or to create a similar looking effect without
6 // transparency.
7 //
8 // Copyright Bob Friesenhahn, 2000
9 //
10 // Usage: detrans color file...
11 //
12 
13 #include <Magick++.h>
14 #include <iostream>
15 using namespace std;
16 using namespace Magick;
17 int main(int argc,char **argv)
18 {
19  if ( argc < 3 )
20  {
21  cout << "Usage: " << argv[0] << " background_color file..." << endl;
22  exit( 1 );
23  }
24 
25  // Initialize ImageMagick install location for Windows
26  InitializeMagick(*argv);
27 
28  {
29  Color color;
30  try {
31  color = Color(argv[1]);
32  }
33  catch ( Exception &error_ )
34  {
35  cout << error_.what() << endl;
36  cout.flush();
37  exit(1);
38  }
39 
40  char **arg = &argv[2];
41  while ( *arg )
42  {
43  string fname(*arg);
44  try {
45  Image overlay( fname );
46  Image base( overlay.size(), color );
47  base.composite( overlay, 0, 0, OverCompositeOp );
48  base.alpha( false );
49  base.write( fname );
50  }
51  catch( Exception &error_ )
52  {
53  cout << error_.what() << endl;
54  }
55  ++arg;
56  }
57  }
58 
59  return 0;
60 }
virtual const char * what() const
Definition: Exception.cpp:56
class MagickPPExport Color
Definition: Color.h:16
int main(int argc, char **argv)
Definition: detrans.cpp:17
void composite(const Image &compositeImage_, const Geometry &offset_, const CompositeOperator compose_=InCompositeOp)
Definition: Image.cpp:2522
STL namespace.
void size(const Geometry &geometry_)
Definition: Image.cpp:1366
Definition: Blob.h:15
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:43