<metaname="description"content="Use ImageMagick® to create, edit, compose, and convert bitmap images. Resize an image, crop it, change its shades and colors, add captions, and more."/>
<pclass="lead magick-description"><ahref="api/Magick++/index.html">Magick++ API</a> is the object-oriented C++ API to the <ahref="../">ImageMagick</a> image-processing library.</p>
<p>Magick++ supports an object model which is inspired by <ahref="../www/perl-magick.html">PerlMagick</a>.
Images support implicit reference counting so that copy constructors
and assignment incur almost no cost. The cost of actually copying an
image (if necessary) is done just before modification and this copy
is managed automagically by Magick++. De-referenced copies are
automagically deleted. The image objects support value (rather than
pointer) semantics so it is trivial to support multiple generations
of an image in memory at one time.
</p>
<p>Magick++ provides integrated support for the <ahref="http://www.sgi.com/tech/stl/">Standard
Template Library</a> (STL) so that the powerful containers available
and <ahref="http://www.sgi.com/tech/stl/Map.html">map</a>) can
be used to write programs similar to those possible with PERL &
PerlMagick. STL-compatible template versions of ImageMagick's
list-style operations are provided so that operations may be
performed on multiple images stored in STL containers.
</p>
<h2>Documentation</h2>
<aclass="anchor"id="documentation"></a>
<p>Detailed <ahref="https://legacy.imagemagick.org/api/magick++-classes.html">documentation</a> is
provided for all Magick++ classes, class methods, and template
functions which comprise the API. See a <ahref="../Magick++/tutorial/Magick++_tutorial.pdf"> Gentle Introduction to Magick++</a> for an introductory tutorial to Magick++. We include the <ahref="../Magick++/tutorial/Magick++_tutorial.odt">source</a> if you want to correct, enhance, or expand the tutorial.</p>
<h2>Obtaining Magick++</h2>
<aclass="anchor"id="get"></a>
<p>Magick++ is included as part of <ahref="../index.html">ImageMagick</a>
source releases and may be retrieved via <ahref="download.html">HTTP</a>
or <ahref="https://github.com/ImageMagick/ImageMagick/tree/main/Magick%2B%2B">GitHub</a>.
</p>
<h2>Installation</h2>
<aclass="anchor"id="install"></a>
<p>Once you have the Magick++ sources available, follow these detailed
<ahref="../Magick++/Install.html">installation instructions</a> for UNIX and
Windows.
</p>
<h2>Usage</h2>
<p>A helper script named <code>Magick++-config</code> is installed
under Unix which assists with recalling compilation options required
to compile and link programs which use Magick++. For example, the
following command compiles and links the source file <code>demo.cpp</code>
to produce the executable <code>demo</code> (notice that quotes are
<p>Windows users may get started by manually editing a project file
for one of the Magick++ demo programs.
</p>
<p>Note, under Windows (and possibly the Mac) it may be necessary to initialize the ImageMagick library prior to using the Magick++ library. This initialization is performed by passing the path to the ImageMagick DLLs (assumed to be in the same directory as your program) to the InitializeMagick() function call. This is commonly performed by providing the path to your program (argv[0]) as shown in the following example: </p>
<preclass="highlight"><code>int main( int argc, char ** argv) {
InitializeMagick(*argv);
...
</code></pre>
<p>This initialization step is not required under Unix, Linux,
Cygwin, or any other operating environment that supports the notion
of <var>installing</var> ImageMagick in a known location. </p>
<p>Here is a example program that utilizes the Magick++ API to get you started, <ahref="https://imagemagick.org/source/magick++.cpp">magick++.cpp</a>. It reads an image, crops it, and writes it to disk in the PNG image format.</p>
<preclass="pre-scrollable"><code>
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
InitializeMagick(*argv);
// Construct the image object. Seperating image construction from the
// the read operation ensures that a failure to read the image file
// doesn't render the image object useless.
Image image;
try {
// Read a file into image object
image.read( "logo:" );
// Crop the image to specified size (width, height, xOffset, yOffset)