The MagickWand API is the recommended interface between the C programming language and the ImageMagick image processing libraries. Unlike the MagickCore C API, MagickWand uses only a few opaque types. Accessors are available to set or get important wand properties. A description of the MagickWand public methods can be found on GitHub:
Compilation & Configuration
After you write your MagickWand program, compile it like this:
$ cc `MagickWand-config --cflags --cppflags` -O2 -o wand wand.c `MagickWand-config --ldflags --libs`
Set the PKG_CONFIG_PATH environment variable if ImageMagick is not in your default system path:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
Example Programs
1. Basic Thumbnail Generator (wand.c)
It reads an image, creates a thumbnail, and writes the result to disk.
2. Pixel-Level Contrast Enhancement (contrast.c)
It reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk.
3. Parallel Contrast Enhancement using Wand Views (sigmoidal-contrast.c)
Perform the same contrast enhancement while taking advantage of dual or quad-core processing systems by running the algorithm in parallel utilizing wand views (assumes ImageMagick is built with OpenMP support).
Resource Management & Termination Notes
MagickWandTerminus() is a function in the ImageMagick library used to clean up and release resources when shutting down an application that uses ImageMagick. This function should be called in the primary thread of the application's process during the shutdown process. It's crucial that this function is invoked only after any threads that are using ImageMagick functions have terminated.
ImageMagick might internally use threads via OpenMP (a method for parallel programming). As a result, it's important to ensure that any function calls into ImageMagick have completed before calling MagickWandTerminus(). This prevents issues with OpenMP worker threads accessing resources that are destroyed by this termination function.
If OpenMP is being used (starting from version 5.0), the OpenMP implementation itself handles starting and stopping worker threads and allocating and freeing resources using its own methods. This means that after calling MagickWandTerminus(), some OpenMP resources and worker threads might still remain allocated. To address this, the function omp_pause_resource_all(omp_pause_hard) can be invoked. This function, introduced in OpenMP version 5.0, ensures that any resources allocated by OpenMP (such as threads and thread-specific memory) are freed. It's recommended to call this function after MagickWandTerminus() has completed its execution.