root / ImageMagick / trunk / www / magick-wand.html

Revision 12661, 13.7 kB (checked in by cristy, 40 hours ago)
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
4<head>
5  <style type="text/css" media="screen,projection"><!--
6    @import url("../www/magick.css");
7  //--></style>
8  <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U=" />
9  <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf" />
10  <title>ImageMagick: MagickWand, C API for ImageMagick</title>
11  <meta http-equiv="Content-Language" content="en-US"/>
12  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
13  <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/>
14  <meta name="Generator" content="PHP"/>
15  <meta name="Keywords" content="magickwc, api, for, imagemagick, ImageMagick, ImageMagic, MagickCore, MagickWand, PerlMagick, Magick++, RMagick, PythonMagick, JMagick, TclMagick, Image, Magick, Magic, Wand, ImageMagickObject"/>
16  <meta name="Description" content="ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.  ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.  The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically."/>
17  <meta name="Rating" content="GENERAL"/>
18  <meta name="Robots" content="INDEX, FOLLOW"/>
19  <meta name="Generator" content="ImageMagick Studio LLC"/>
20  <meta name="Author" content="ImageMagick Studio LLC"/>
21  <meta name="Revisit-after" content="2 DAYS"/>
22  <meta name="Resource-type" content="document"/>
23  <meta name="Copyright" content="Copyright (c) 1999-2008 ImageMagick Studio LLC"/>
24  <meta name="Distribution" content="Global"/>
25  <link rel="shortcut icon" href="../images/wand.ico"  type="images/vnd.microsoft.icon"/>
26</head>
27
28<body id="www-imagemagick-org">
29  <table id="titlebar" style="width: 100%;background-color: #f5f5f5" cellpadding="0" cellspacing="0" border="0" summary="ImageMagick">
30    <tbody>
31      <tr valign="top">
32        <td align="left"><a href="../index.html"><img id="titlebar-west" src="../images/script.png" alt="[ImageMagick]" width="350" height="60" vspace="28" name="titlebar-west"/></a></td>
33        <td align="left"><a href="https://secure.networkredux.com/affiliate/idevaffiliate.html?id=146" target="2142014611"><img id="titlebar-west" src="../images/networkredux.png" alt="[sponsor]" border="0" vspace="45" name="titlebar-west"/></a></td>
34        <td width="99%"><br /> </td>
35        <td style="background-color: white" align="right"><a href="../index.html"><img src="../images/sprite.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td>
36        <td style="background-color: white" align="right"><a href="http://www.imagemagick.org/discourse-server/" target="1472829321"><img id="titlebar-east" src="../images/logo.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td>
37      </tr>
38    </tbody>
39  </table>
40
41  <table style="width: 100%" border="0" cellpadding="0" cellspacing="0" summary="">
42  <tbody>
43
44    <tr valign="top" style="height: 100%;">
45      <td id="menu" width="1%" height="100%">
46      <p><a href="#main">Skip to page contents</a></p>
47      <font size="-1">
48      <span>[</span>
49      <a href="../index.html">About ImageMagick</a>
50  <span>]</span><br /><span>[</span>
51      <a href="../www/command-line-tools.html">Command-line Tools</a>
52      <a href="../www/command-line-processing.html" class="sub">Processing</a>
53      <a href="../www/command-line-options.html" class="sub">Options</a>
54      <a href="http://www.imagemagick.org/Usage/" target="1920762708" class="sub">Usage</a>
55      <a href="../www/api.html">Program Interfaces</a>
56      <a href="../www/magick-wand.html" class="sub">MagickWand</a>
57      <a href="../www/magick-core.html" class="sub">MagickCore</a>
58      <a href="../www/perl-magick.html" class="sub">PerlMagick</a>
59      <a href="../www/Magick++/" target="821294292" class="sub">Magick++</a>
60      <a href="../www/architecture.html">Architecture</a>
61  <span>]</span><br /><span>[</span>
62      <a href="../www/install-source.html">Install from Source</a>
63      <a href="../www/install-source.html#unix" class="sub">Unix</a>
64      <a href="../www/install-source.html#windows" class="sub">Windows</a>
65      <a href="../www/binary-releases.html">Binary Releases</a>
66      <a href="../www/binary-releases.html#unix" class="sub">Unix</a>
67      <a href="../www/binary-releases.html#macosx" class="sub">Mac OS X</a>
68      <a href="../www/binary-releases.html#windows" class="sub">Windows</a>
69      <a href="../www/resources.html">Resources</a>
70  <span>]</span><br /><span>[</span>
71      <a href="../www/download.html">Download</a>
72  <span>]</span><br /><span>[</span>
73      <a href="../www/sitemap.html">Site Map</a>
74                        <a href="../www/links.html" class="sub">Links</a>
75  <span>]</span><br /><span>[</span>
76      <a href="../www/sponsors.html">Sponsors:</a>
77      <fieldset>
78  <a href="http://www.wiiusers.net" class="sponsor" target="sponsor">Wii Forums</a><!-- 200901010000 -->
79      <br />
80      <a href="http://meta-preisvergleich.de" class="sponsor" target="sponsor">Preisvergleich</a><!-- 200901010120 -->
81      <br />
82      <a href="http://www.checkcost.co.uk" class="sponsor" target="sponsor">Compare</a><!-- 200902010720 -->
83      <br />
84      <a href="http://www.ecostsoftware.com" class="sponsor" target="sponsor">Software</a><!-- 200902010720 -->
85      <br />
86      <a href="http://www.callerbase.com" class="sponsor" target="sponsor">Phone Number<br />Search</a><!-- 200812010040 -->
87      <br />
88      <a href="http://www.online-kredit-index.de" class="sponsor" target="sponsor">Kredit</a><!-- 200903010120 -->
89      <br />
90      <a href="http://www.posters555.com" class="sponsor" target="sponsor">Poster</a><!-- 200903010800 -->
91      <br />
92      <a href="http://www.iceposter.com" class="sponsor" target="sponsor">Posters</a><!-- 200812010200 -->
93      <br />
94      <a href="http://www.imade-art.de"><img src="../images/imade_art2.jpg" alt="[Kunst bei imade-art]" width="116" height="28" border="0" name="Kunst bei imade-art"/></a> <!-- 200811010160 -->
95      </fieldset>
96      <span>]</span>
97      </font>
98      </td>
99
100      <td id="main" valign="top">
101<p>The <a href="../www/api/MagickWand/index.html"  target="1275210070">MagickWand API</a> is the recommended interface between the C programming language and the ImageMagick image processing libraries.  Unlike the <a href="../www/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>
102
103<ul>
104  <li><a href="../www/api/magick-wand.html">Magick Wand Methods</a></li>
105  <li><a href="../www/api/magick-property.html">Set or Get Magick Wand Properties</a></li>
106  <li><a href="../www/api/magick-image.html">Magick Wand Image Methods</a></li>
107  <li><a href="../www/api/pixel-iterator.html">Pixel Iterator Methods</a></li>
108  <li><a href="../www/api/pixel-view.html">Pixel View Methods</a></li>
109  <li><a href="../www/api/pixel-wand.html">Pixel Wand Methods</a></li>
110  <li><a href="../www/api/drawing-wand.html">Image Vector Drawing</a></li>
111  <li><a href="../www/api/magick-deprecate.html">Deprecated Methods</a></li>
112</ul>
113
114<p>After you write your MagickWand program, compile it like this:</p>
115
116<pre class="text">
117  cc `MagickWand-config --cflags --cppflags` wand.c `MagickWand-config --ldflags --libs`
118</pre>
119
120<p>Here is a example program that utilizes the MagickWand API to get you started, <a href="../www/source/wand.c">wand.c</a>. It reads an image, creates a thumbnail, and writes the result to disk.</p>
121
122<div class="viewport">
123<pre class="code">
124#include &lt;stdio.h>
125#include &lt;stdlib.h>
126#include &lt;wand/MagickWand.h>
127
128int main(int argc,char **argv)
129{
130#define ThrowWandException(wand) \
131{ \
132  char \
133    *description; \
134 \
135  ExceptionType \
136    severity; \
137 \
138  description=MagickGetException(wand,&severity); \
139  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
140  description=(char *) MagickRelinquishMemory(description); \
141  exit(-1); \
142}
143
144  MagickBooleanType
145    status;
146
147  MagickWand
148    *magick_wand;
149
150  if (argc != 3)
151    {
152      (void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]);
153      exit(0);
154    }
155  /*
156    Read an image.
157  */
158  MagickWandGenesis();
159  magick_wand=NewMagickWand(); 
160  status=MagickReadImage(magick_wand,argv[1]);
161  if (status == MagickFalse)
162    ThrowWandException(magick_wand);
163  /*
164    Turn the images into a thumbnail sequence.
165  */
166  MagickResetIterator(magick_wand);
167  while (MagickNextImage(magick_wand) != MagickFalse)
168    MagickResizeImage(magick_wand,106,80,LanczosFilter,1.0);
169  /*
170    Write the image then destroy it.
171  */
172  status=MagickWriteImages(magick_wand,argv[2],MagickTrue);
173  if (status == MagickFalse)
174    ThrowWandException(magick_wand);
175  magick_wand=DestroyMagickWand(magick_wand);
176  MagickWandTerminus();
177  return(0);
178}
179</pre>
180</div>
181
182<p>Here is another program that shows one way to get and set image pixels with the MagickWand API, <a href="../www/source/contrast.c">contrast.c</a>. It reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk.</p>
183
184<div class="viewport">
185<pre class="code">
186#include &lt;stdio.h>
187#include &lt;stdlib.h>
188#include &lt;math.h>
189#include &lt;wand/MagickWand.h>
190
191int main(int argc,char **argv)
192{
193#define QuantumScale  ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
194#define SigmoidalContrast(x) \
195  (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)
196#define ThrowWandException(wand) \
197{ \
198  char \
199    *description; \
200 \
201  ExceptionType \
202    severity; \
203 \
204  description=MagickGetException(wand,&severity); \
205  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
206  description=(char *) MagickRelinquishMemory(description); \
207  exit(-1); \
208}
209
210  long
211    y;
212
213  MagickBooleanType
214    status;
215
216  MagickPixelPacket
217    pixel;
218
219  MagickWand
220    *contrast_wand,
221    *image_wand;
222
223  PixelIterator
224    *contrast_iterator,
225    *iterator;
226
227  PixelWand
228    **contrast_pixels,
229    **pixels;
230
231  register long
232    x;
233
234  unsigned long
235    width;
236
237  if (argc != 3)
238    {
239      (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]);
240      exit(0);
241    }
242  /*
243    Read an image.
244  */
245  MagickWandGenesis();
246  image_wand=NewMagickWand();
247  status=MagickReadImage(image_wand,argv[1]);
248  if (status == MagickFalse)
249    ThrowWandException(image_wand);
250  contrast_wand=CloneMagickWand(image_wand);
251  /*
252    Sigmoidal non-linearity contrast control.
253  */
254  iterator=NewPixelIterator(image_wand);
255  contrast_iterator=NewPixelIterator(contrast_wand);
256  if ((iterator == (PixelIterator *) NULL) ||
257      (contrast_iterator == (PixelIterator *) NULL))
258    ThrowWandException(image_wand);
259  for (y=0; y < (long) MagickGetImageHeight(image_wand); y++)
260  {
261    pixels=PixelGetNextIteratorRow(iterator,&width);
262    contrast_pixels=PixelGetNextIteratorRow(contrast_iterator,&width);
263    if ((pixels == (PixelWand **) NULL) ||
264        (contrast_pixels == (PixelWand **) NULL))
265      break;
266    for (x=0; x < (long) width; x++)
267    {
268      PixelGetMagickColor(pixels[x],&pixel);
269      pixel.red=SigmoidalContrast(pixel.red);
270      pixel.green=SigmoidalContrast(pixel.green);
271      pixel.blue=SigmoidalContrast(pixel.blue);
272      pixel.index=SigmoidalContrast(pixel.index);
273      PixelSetMagickColor(contrast_pixels[x],&pixel);
274    }
275    (void) PixelSyncIterator(contrast_iterator);
276  }
277  if (y < (long) MagickGetImageHeight(image_wand))
278    ThrowWandException(image_wand);
279  contrast_iterator=DestroyPixelIterator(contrast_iterator);
280  iterator=DestroyPixelIterator(iterator);
281  image_wand=DestroyMagickWand(image_wand);
282  /*
283    Write the image then destroy it.
284  */
285  status=MagickWriteImages(contrast_wand,argv[2],MagickTrue);
286  if (status == MagickFalse)
287    ThrowWandException(image_wand);
288  contrast_wand=DestroyMagickWand(contrast_wand);
289  MagickWandTerminus();
290  return(0);
291}
292</pre>
293</div>
294      </td>
295      <td id="margin" width="1%" height="100%" valign="top" align="right">&nbsp;</td>
296    </tr>
297  </tbody>
298  </table>
299  <div id="linkbar">
300    <span id="linkbar-west">
301      <font size="-1">
302      </font>
303    </span>
304    <span id="linkbar-center">
305      <a href="http://www.imagemagick.org/discourse-server/" target="1914729927">Discourse Server</a> &bull;
306      <a href="../www/mailing-list.html">Mailing Lists</a> &bull;
307      <a href="http://cafe.imagemagick.org" target="1865062727">Cafe</a> &bull;
308    <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi" target="344852483">Studio</a>
309    </span>
310    <span id="linkbar-east">
311      <font size="-1">
312      </font>
313    </span>
314  </div>
315  <div id="footer">
316    <span id="footer-west">&copy; 1999-2008 ImageMagick Studio LLC</span>
317  </div>
318  <div style="clear: both; margin: 0; width: 100%; "></div>
319</body>
320</html>
Note: See TracBrowser for help on using the browser.