Magick++  7.1.0
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 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
11 // dedicated to making software imaging solutions freely available.
12 //
13 // Usage: detrans color file...
14 //
15 
16 #include <Magick++.h>
17 #include <iostream>
18 using namespace std;
19 using namespace Magick;
20 int main(int argc,char **argv)
21 {
22  if ( argc < 3 )
23  {
24  cout << "Usage: " << argv[0] << " background_color file..." << endl;
25  exit( 1 );
26  }
27 
28  // Initialize ImageMagick install location for Windows
29  InitializeMagick(*argv);
30 
31  {
32  Color color;
33  try {
34  color = Color(argv[1]);
35  }
36  catch ( Exception &error_ )
37  {
38  cout << error_.what() << endl;
39  cout.flush();
40  exit(1);
41  }
42 
43  char **arg = &argv[2];
44  while ( *arg )
45  {
46  string fname(*arg);
47  try {
48  Image overlay( fname );
49  Image base( overlay.size(), color );
50  base.composite( overlay, 0, 0, OverCompositeOp );
51  base.alpha( false );
52  base.write( fname );
53  }
54  catch( Exception &error_ )
55  {
56  cout << error_.what() << endl;
57  }
58  ++arg;
59  }
60  }
61 
62  return 0;
63 }
virtual const char * what() const
Definition: Exception.cpp:58
class MagickPPExport Color
Definition: Color.h:18
int main(int argc, char **argv)
Definition: detrans.cpp:20
void composite(const Image &compositeImage_, const Geometry &offset_, const CompositeOperator compose_=InCompositeOp)
Definition: Image.cpp:2535
STL namespace.
void size(const Geometry &geometry_)
Definition: Image.cpp:1379
Definition: Blob.h:17
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45