ImageMagick has a number of functions that allow you to read, manipulate, write, or display an image. These functions are accessible through the various tools or the object-oriented Perl interface, PerlMagick. However, you can also access the functions directly from your program through the Magick Application Programmer Interface. To invoke the functions, write your program in your favorite language while making calls to the Magick image functions and link with libMagick.a, libMagick.so, or Magick.dll depending on your system.
The API is divided into a number of categories:
Here is a full example of a program, example.c, that reads a JPEG image, creates a thumbnail, and writes it to disk in the PNG image format.
#include <stdio.h> #include <time.h> #include <sys/types.h> #include <magick/api.h> int main(int argc,char **argv) { ExceptionInfo exception; Image *image, *zoom_image; ImageInfo *image_info; /* Initialize the image info structure and read an image. */ MagickIncarnate(*argv); GetExceptionInfo(&exception); image_info=CloneImageInfo((ImageInfo *) NULL); (void) strcpy(image_info->filename,"image.jpg"); image=ReadImage(image_info,&exception); if (image == (Image *) NULL) MagickError(exception.severity,exception.reason,exception.description); /* Turn the image into a thumbnail. */ zoom_image=ZoomImage(image,106,80,&exception); if (zoom_image == (Image *) NULL) MagickError(exception.severity,exception.reason,exception.description); DestroyImage(image); image=zoom_image; /* Write the image as PNG and destroy it. */ (void) strcpy(image->filename,"image.png"); WriteImage(image_info,image); DestroyImageInfo(image_info); DestroyImage(image); return(0); }Now we need to compile. On Unix, the command would look something like this:
gcc `Magick-config --cflags --cppflags` example.c `Magick-config --ldflags --libs`Another example is smile.c. Compile and excute it to display a smiley face on your X server.
For C++, use:
g++ `Magick++-config --cxxflags --cppflags` demo.cpp `Magick++-config --ldflags --libs`