8 <meta charset="utf-8" />
9 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
10 <meta http-equiv="x-ua-compatible" content="ie=edge" />
11 <title>MagickWand, C API @ ImageMagick</title>
12 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
13 <meta name="application-name" content="ImageMagick"/>
14 <meta name="description" content="ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, JPEG-2000, GIF, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves."/>
15 <meta name="application-url" content="https://www.imagemagick.org"/>
16 <meta name="generator" content="PHP"/>
17 <meta name="keywords" content="magickwc, api, ImageMagick, PerlMagick, image processing, image, photo, software, Magick++, OpenMP, convert"/>
18 <meta name="rating" content="GENERAL"/>
19 <meta name="robots" content="INDEX, FOLLOW"/>
20 <meta name="generator" content="ImageMagick Studio LLC"/>
21 <meta name="author" content="ImageMagick Studio LLC"/>
22 <meta name="revisit-after" content="2 DAYS"/>
23 <meta name="resource-type" content="document"/>
24 <meta name="copyright" content="Copyright (c) 1999-2017 ImageMagick Studio LLC"/>
25 <meta name="distribution" content="Global"/>
26 <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1"/>
27 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" />
28 <link rel="canonical" href="https://www.imagemagick.org/script/magick-wand.html"/>
29 <link rel="icon" href="../images/wand.png"/>
30 <link rel="shortcut icon" href="../images/wand.ico"/>
31 <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:900,400,400italic,700,700italic,300,300italic|Open+Sans:300italic,400italic,700italic,300,400,600,700" />
32 <link rel="stylesheet" href="css/magick.css"/>
36 <div class="magick-masthead">
37 <div class="container">
38 <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle"
40 data-ad-client="ca-pub-3129977114552745"
41 data-ad-slot="6345125851"
42 data-ad-format="auto"></ins>
44 (adsbygoogle = window.adsbygoogle || []).push({});
46 <nav class="magick-nav">
47 <a class="magick-nav-item " href="../index.html">Home</a>
48 <a class="magick-nav-item " href="download.html">Download</a>
49 <a class="magick-nav-item " href="command-line-tools.html">Tools</a>
50 <a class="magick-nav-item " href="command-line-processing.html">Command-line</a>
51 <a class="magick-nav-item " href="resources.html">Resources</a>
52 <a class="magick-nav-item " href="develop.html">Develop</a>
53 <a class="magick-nav-item " href="https://www.imagemagick.org/script/search.php">Search</a>
54 <a class="magick-nav-item pull-right" href="https://www.imagemagick.org/discourse-server/">Community</a>
58 <div class="container">
59 <div class="magick-header">
61 <p class="lead magick-description">The <a href="http://www.imagemagick.org/api/MagickWand/index.html">MagickWand API</a> is the recommended interface between the C programming language and the ImageMagick image processing libraries. Unlike the <a href="magick-core.html">MagickCore</a> 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 are found here:</p>
64 <li><a href="http://www.imagemagick.org/api/magick-wand.html">Magick Wand Methods</a></li>
65 <li><a href="http://www.imagemagick.org/api/magick-property.html">Set or Get Magick Wand Properties</a></li>
66 <li><a href="http://www.imagemagick.org/api/magick-image.html">Magick Wand Image Methods</a></li>
67 <li><a href="http://www.imagemagick.org/api/pixel-iterator.html">Pixel Iterator Methods</a></li>
68 <li><a href="http://www.imagemagick.org/api/pixel-wand.html">Pixel Wand Methods</a></li>
69 <li><a href="http://www.imagemagick.org/api/drawing-wand.html">Image Vector Drawing</a></li>
70 <li><a href="http://www.imagemagick.org/api/mogrify.html">Command-line Interface</a></li>
71 <li><a href="api/wand-view.html">Wand View Methods</a></li>
72 <li><a href="http://www.imagemagick.org/api/magick-deprecate.html">Deprecated Methods</a></li>
73 <li><a href="exception.html">Error and Warning Codes</a></li>
76 <p>After you write your MagickWand program, compile it like this:</p>
79 cc -o wand wand.c `pkg-config --cflags --libs MagickWand`
82 <p>Set the <code>PKG_CONFIG_PATH</code> environment variable if ImageMagick is not in your default system path:</p>
85 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
88 <p>Here is a example program that utilizes the MagickWand API to get you started, <a href="http://www.imagemagick.org/source/wand.c">wand.c</a>. It reads an image, creates a thumbnail, and writes the result to disk.</p>
90 <pre class="pre-scrollable">#include <stdio.h>
91 #include <stdlib.h>
92 #include <wand/MagickWand.h>
94 int main(int argc,char **argv)
96 #define ThrowWandException(wand) \
104 description=MagickGetException(wand,&severity); \
105 (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
106 description=(char *) MagickRelinquishMemory(description); \
118 (void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]);
125 magick_wand=NewMagickWand();
126 status=MagickReadImage(magick_wand,argv[1]);
127 if (status == MagickFalse)
128 ThrowWandException(magick_wand);
130 Turn the images into a thumbnail sequence.
132 MagickResetIterator(magick_wand);
133 while (MagickNextImage(magick_wand) != MagickFalse)
134 MagickResizeImage(magick_wand,106,80,LanczosFilter,1.0);
136 Write the image then destroy it.
138 status=MagickWriteImages(magick_wand,argv[2],MagickTrue);
139 if (status == MagickFalse)
140 ThrowWandException(magick_wand);
141 magick_wand=DestroyMagickWand(magick_wand);
142 MagickWandTerminus();
147 <p>Here is another program that shows one way to get and set image pixels with the MagickWand API, <a href="http://www.imagemagick.org/source/contrast.c">contrast.c</a>. It reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk.</p>
149 <pre class="pre-scrollable">#include <stdio.h>
150 #include <stdlib.h>
152 #include <wand/MagickWand.h>
154 int main(int argc,char **argv)
156 #define QuantumScale ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
157 #define SigmoidalContrast(x) \
158 (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)
159 #define ThrowWandException(wand) \
167 description=MagickGetException(wand,&severity); \
168 (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
169 description=(char *) MagickRelinquishMemory(description); \
202 (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]);
209 image_wand=NewMagickWand();
210 status=MagickReadImage(image_wand,argv[1]);
211 if (status == MagickFalse)
212 ThrowWandException(image_wand);
213 contrast_wand=CloneMagickWand(image_wand);
215 Sigmoidal non-linearity contrast control.
217 iterator=NewPixelIterator(image_wand);
218 contrast_iterator=NewPixelIterator(contrast_wand);
219 if ((iterator == (PixelIterator *) NULL) ||
220 (contrast_iterator == (PixelIterator *) NULL))
221 ThrowWandException(image_wand);
222 for (y=0; y < (long) MagickGetImageHeight(image_wand); y++)
224 pixels=PixelGetNextIteratorRow(iterator,&width);
225 contrast_pixels=PixelGetNextIteratorRow(contrast_iterator,&width);
226 if ((pixels == (PixelWand **) NULL) ||
227 (contrast_pixels == (PixelWand **) NULL))
229 for (x=0; x < (long) width; x++)
231 PixelGetMagickColor(pixels[x],&pixel);
232 pixel.red=SigmoidalContrast(pixel.red);
233 pixel.green=SigmoidalContrast(pixel.green);
234 pixel.blue=SigmoidalContrast(pixel.blue);
235 pixel.index=SigmoidalContrast(pixel.index);
236 PixelSetMagickColor(contrast_pixels[x],&pixel);
238 (void) PixelSyncIterator(contrast_iterator);
240 if (y < (long) MagickGetImageHeight(image_wand))
241 ThrowWandException(image_wand);
242 contrast_iterator=DestroyPixelIterator(contrast_iterator);
243 iterator=DestroyPixelIterator(iterator);
244 image_wand=DestroyMagickWand(image_wand);
246 Write the image then destroy it.
248 status=MagickWriteImages(contrast_wand,argv[2],MagickTrue);
249 if (status == MagickFalse)
250 ThrowWandException(image_wand);
251 contrast_wand=DestroyMagickWand(contrast_wand);
252 MagickWandTerminus();
256 <p><a id="wand-view"></a>Now lets perform the same contrast enhancement while taking advantage of our dual or quad-core processing system by running the algorithm in parallel utilizing wand views. The <a href="http://www.imagemagick.org/source/wand/sigmoidal-contrast.c">sigmoidal-contrast.c</a> module reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk just like the previous contrast enhancement program, but now it does its work in parallel (assumes ImageMagick is built with OpenMP support).</p>
258 <pre class="pre-scrollable">#include <stdio.h>
259 #include <stdlib.h>
261 #include <wand/MagickWand.h>
263 static MagickBooleanType SigmoidalContrast(WandView *pixel_view,
264 const ssize_t y,const int id,void *context)
266 #define QuantumScale ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
267 #define SigmoidalContrast(x) \
268 (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)
282 extent=GetWandViewExtent(contrast_view);
283 pixels=GetWandViewPixels(contrast_view);
284 for (x=0; x < (long) (extent.width-extent.height); x++)
286 PixelGetMagickColor(pixels[x],&pixel);
287 pixel.red=SigmoidalContrast(pixel.red);
288 pixel.green=SigmoidalContrast(pixel.green);
289 pixel.blue=SigmoidalContrast(pixel.blue);
290 pixel.index=SigmoidalContrast(pixel.index);
291 PixelSetMagickColor(contrast_pixels[x],&pixel);
296 int main(int argc,char **argv)
298 #define ThrowViewException(view) \
300 description=GetWandViewException(view,&severity); \
301 (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
302 description=(char *) MagickRelinquishMemory(description); \
305 #define ThrowWandException(wand) \
307 description=MagickGetException(wand,&severity); \
308 (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
309 description=(char *) MagickRelinquishMemory(description); \
333 (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]);
340 contrast_wand=NewMagickWand();
341 status=MagickReadImage(contrast_wand,argv[1]);
342 if (status == MagickFalse)
343 ThrowWandException(contrast_wand);
345 Sigmoidal non-linearity contrast control.
347 contrast_view=NewWandView(contrast_wand);
348 if (contrast_view == (WandView *) NULL)
349 ThrowWandException(contrast_wand);
350 status=UpdateWandViewIterator(contrast_view,SigmoidalContrast,(void *) NULL);
351 if (status == MagickFalse)
352 ThrowWandException(contrast_wand);
353 contrast_view=DestroyWandView(contrast_view);
355 Write the image then destroy it.
357 status=MagickWriteImages(contrast_wand,argv[2],MagickTrue);
358 if (status == MagickFalse)
359 ThrowWandException(contrast_wand);
360 contrast_wand=DestroyMagickWand(contrast_wand);
361 MagickWandTerminus();
365 <p><a href="http://members.shaw.ca/el.supremo/MagickWand/">MagickWand Examples in C</a> illustrates how to use the ImageMagick MagickWand API. Each example is presented as a C function, complete with headers, so that it can be copied to a file and then included in your own C project.</p>
367 <footer class="magick-footer">
368 <p><a href="support.html">Donate</a> •
369 <a href="sitemap.html">Sitemap</a> •
370 <a href="links.html">Related</a> •
371 <a href="security-policy.html">Security</a> •
372 <a href="architecture.html">Architecture</a>
374 <p><a href="magick-wand.html#">Back to top</a> •
375 <a href="http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> •
376 <a href="https://www.imagemagick.org/script/contact.php">Contact Us</a></p>
377 <p><small>© 1999-2017 ImageMagick Studio LLC</small></p>
379 </div><!-- /.container -->
381 <script src="https://localhost/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
382 <script src="../js/magick.html"></script>
386 <!-- Magick Cache 21st January 2017 12:17 -->