Skip to content

Commit 54dcae7

Browse files
committed
Merge branch 'drawing' of github.com:dahlia/wand
2 parents 428a91b + 57e008b commit 54dcae7

File tree

14 files changed

+1202
-8
lines changed

14 files changed

+1202
-8
lines changed

docs/changes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Version 0.3.0
66

77
To be released.
88

9+
- Added :mod:`wand.drawing` module. [:issue:`64` by Adrian Jung]
10+
- Added :meth:`Drawing.get_font_metrics()
11+
<wand.drawing.Drawing.get_font_metrics>` method.
12+
[:issue:`69`, :issue:`71` by Cha, Hojeong]
13+
- Added :meth:`Image.caption() <wand.image.Image.caption>` method.
14+
[:issue:`74` by Cha, Hojeong]
915
- Added optional ``color`` parameter to :meth:`Image.border()
1016
<wand.image.Image.border>` method.
1117
- Added :meth:`Image.border() <wand.image.Image.border>` method.

docs/guide/draw.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Drawing
2+
=======
3+
4+
.. versionadded:: 0.3.0
5+
6+
The :mod:`wand.drawing` module provides some basic drawing functions.
7+
:class:`wand.drawing.Drawing` object buffers instructions for drawing
8+
shapes into images, and then it can draw these shapes into zero or more
9+
images.
10+
11+
It's also callable and takes an :class:`~wand.image.Image` object::
12+
13+
from wand.drawing import Drawing
14+
from wand.image import Image
15+
16+
with Drawing() as draw:
17+
# does something with ``draw`` object,
18+
# and then...
19+
with Image(filename='wandtests/assets/beach.jpg') as image:
20+
draw(image)
21+
22+
23+
Lines
24+
-----
25+
26+
You can draw lines using :meth:`~wand.drawing.Drawing.line()` method.
27+
It simply takes two (x, y) coordinates for start and end of a line.
28+
For example, the following code draws a diagonal line into the ``image``::
29+
30+
draw.line((0, 0), image.size)
31+
draw(image)
32+
33+
Or you can turn this diagonal line upside down::
34+
35+
draw.line((0, image.height), (image.width, 0))
36+
draw(image)
37+
38+
The line color is determined by :attr:`~wand.drawing.Drawing.fill_color`
39+
property, and you can change this of course. The following code draws
40+
a red diagonal line into the ``image``::
41+
42+
from wand.color import Color
43+
44+
with Color('red') as color:
45+
draw.fill_color = color
46+
draw.line((0, 0), image.size)
47+
draw(image)
48+
49+
50+
Texts
51+
-----
52+
53+
:class:`~wand.drawing.Drawing` object can write texts as well using its
54+
:meth:`~wand.drawing.Drawing.text()` method. It takes ``x`` and ``y``
55+
cordinates to be drawn and a string to write::
56+
57+
draw.font = 'wandtests/assets/League_Gothic.otf'
58+
draw.font_size = 40
59+
draw.text(image.width / 2, image.height / 2, 'Hello, world!')
60+
draw(image)
61+
62+
As the above code shows you can adjust several settings before writing texts:
63+
64+
- :attr:`~wand.drawing.Drawing.font`
65+
- :attr:`~wand.drawing.Drawing.font_size`
66+
- :attr:`~wand.drawing.Drawing.gravity`
67+
- :attr:`~wand.drawing.Drawing.text_alignment`
68+
- :attr:`~wand.drawing.Drawing.text_antialias`
69+
- :attr:`~wand.drawing.Drawing.text_decoration`
70+
- :attr:`~wand.drawing.Drawing.text_interline_spacing`
71+
- :attr:`~wand.drawing.Drawing.text_interword_spacing`
72+
- :attr:`~wand.drawing.Drawing.text_kerning`
73+
- :attr:`~wand.drawing.Drawing.text_under_color`

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ User's guide
6363
guide/read
6464
guide/write
6565
guide/resizecrop
66+
guide/draw
6667
guide/exif
6768
guide/resource
6869
test

docs/wand.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
wand/image
99
wand/color
10+
wand/font
11+
wand/drawing
1012
wand/resource
1113
wand/exceptions
1214
wand/api

docs/wand/drawing.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
.. automodule:: wand.drawing
3+
:members:

docs/wand/font.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
.. automodule:: wand.font
3+
:members:

wand/api.py

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class MagickPixelPacket(ctypes.Structure):
218218
library.MagickWriteImageFile.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
219219

220220
library.MagickGetImageResolution.argtypes = [
221-
ctypes.c_void_p, ctypes.POINTER(ctypes.c_double),
221+
ctypes.c_void_p,
222222
ctypes.POINTER(ctypes.c_double)
223223
]
224224

@@ -228,7 +228,6 @@ class MagickPixelPacket(ctypes.Structure):
228228

229229
library.MagickSetResolution.argtypes = [ctypes.c_void_p, ctypes.c_double,
230230
ctypes.c_double]
231-
library.MagickSetResolution.restype = ctypes.c_bool
232231

233232
library.MagickGetImageWidth.argtypes = [ctypes.c_void_p]
234233
library.MagickGetImageWidth.restype = ctypes.c_size_t
@@ -372,12 +371,195 @@ class MagickPixelPacket(ctypes.Structure):
372371

373372
library.MagickTrimImage.argtypes = [ctypes.c_void_p]
374373

374+
library.MagickGetSize.argtypes = [ctypes.c_void_p,
375+
ctypes.POINTER(ctypes.c_uint),
376+
ctypes.POINTER(ctypes.c_uint)]
377+
library.MagickGetSize.restype = ctypes.c_int
378+
379+
library.MagickSetSize.argtypes = [ctypes.c_void_p,
380+
ctypes.c_uint,
381+
ctypes.c_uint]
382+
library.MagickSetSize.restype = ctypes.c_int
383+
384+
library.MagickGetFont.argtypes = [ctypes.c_void_p]
385+
library.MagickGetFont.restype = ctypes.c_char_p
386+
387+
library.MagickSetFont.argtypes = [ctypes.c_void_p,
388+
ctypes.c_char_p]
389+
library.MagickSetFont.restype = ctypes.c_int
390+
391+
library.MagickGetPointsize.argtypes = [ctypes.c_void_p]
392+
library.MagickGetPointsize.restype = ctypes.c_double
393+
394+
library.MagickSetPointsize.argtypes = [ctypes.c_void_p,
395+
ctypes.c_double]
396+
library.MagickSetPointsize.restype = ctypes.c_int
397+
398+
library.MagickGetGravity.argtypes = [ctypes.c_void_p]
399+
library.MagickGetGravity.restype = ctypes.c_int
400+
401+
library.MagickSetGravity.argtypes = [ctypes.c_void_p,
402+
ctypes.c_int]
403+
library.MagickSetGravity.restype = ctypes.c_int
404+
405+
library.MagickSetLastIterator.argtypes = [ctypes.c_void_p]
406+
407+
library.MagickGetBackgroundColor.argtypes = [ctypes.c_void_p]
408+
library.MagickGetBackgroundColor.restype = ctypes.c_void_p
409+
410+
library.MagickSetBackgroundColor.argtypes = [ctypes.c_void_p,
411+
ctypes.c_void_p]
412+
library.MagickSetBackgroundColor.restype = ctypes.c_int
413+
414+
library.MagickGetOption.argtypes = [ctypes.c_void_p,
415+
ctypes.c_char_p]
416+
library.MagickGetOption.restype = ctypes.c_char_p
417+
418+
library.MagickSetOption.argtypes = [ctypes.c_void_p,
419+
ctypes.c_char_p,
420+
ctypes.c_char_p]
421+
library.MagickSetOption.restype = ctypes.c_int
422+
423+
library.MagickGetAntialias.argtypes = [ctypes.c_void_p]
424+
library.MagickGetAntialias.restype = ctypes.c_int
425+
426+
library.MagickSetAntialias.argtypes = [ctypes.c_void_p,
427+
ctypes.c_int]
428+
library.MagickSetAntialias.restype = ctypes.c_int
429+
375430
# These functions are const so it's okay for them to be c_char_p
376431
libmagick.GetMagickVersion.argtypes = [ctypes.POINTER(ctypes.c_size_t)]
377432
libmagick.GetMagickVersion.restype = ctypes.c_char_p
378433

379434
libmagick.GetMagickReleaseDate.argtypes = []
380435
libmagick.GetMagickReleaseDate.restype = ctypes.c_char_p
436+
437+
library.NewDrawingWand.restype = ctypes.c_void_p
438+
439+
library.CloneDrawingWand.argtypes = [ctypes.c_void_p]
440+
library.CloneDrawingWand.restype = ctypes.c_void_p
441+
442+
library.DestroyDrawingWand.argtypes = [ctypes.c_void_p]
443+
library.DestroyDrawingWand.restype = ctypes.c_void_p
444+
445+
library.IsDrawingWand.argtypes = [ctypes.c_void_p]
446+
library.IsDrawingWand.restype = ctypes.c_int
447+
448+
library.DrawGetException.argtypes = [ctypes.c_void_p,
449+
ctypes.POINTER(ctypes.c_int)]
450+
library.DrawGetException.restype = ctypes.c_char_p
451+
452+
library.DrawClearException.argtypes = [ctypes.c_void_p]
453+
library.DrawClearException.restype = ctypes.c_int
454+
455+
library.DrawSetFont.argtypes = [ctypes.c_void_p,
456+
ctypes.c_char_p]
457+
458+
library.DrawSetFontSize.argtypes = [ctypes.c_void_p,
459+
ctypes.c_double]
460+
461+
library.DrawSetFillColor.argtypes = [ctypes.c_void_p,
462+
ctypes.c_void_p]
463+
464+
library.DrawSetTextAlignment.argtypes = [ctypes.c_void_p,
465+
ctypes.c_int]
466+
467+
library.DrawSetTextAntialias.argtypes = [ctypes.c_void_p,
468+
ctypes.c_int]
469+
470+
library.DrawSetTextDecoration.argtypes = [ctypes.c_void_p,
471+
ctypes.c_int]
472+
473+
library.DrawSetTextEncoding.argtypes = [ctypes.c_void_p,
474+
ctypes.c_char_p]
475+
476+
library.DrawSetTextInterlineSpacing.argtypes = [ctypes.c_void_p,
477+
ctypes.c_double]
478+
479+
library.DrawSetTextInterwordSpacing.argtypes = [ctypes.c_void_p,
480+
ctypes.c_double]
481+
482+
library.DrawSetTextKerning.argtypes = [ctypes.c_void_p,
483+
ctypes.c_double]
484+
485+
library.DrawSetTextUnderColor.argtypes = [ctypes.c_void_p,
486+
ctypes.c_void_p]
487+
488+
library.DrawGetFillColor.argtypes = [ctypes.c_void_p,
489+
ctypes.c_void_p]
490+
491+
library.DrawGetFont.argtypes = [ctypes.c_void_p]
492+
library.DrawGetFont.restype = ctypes.c_char_p
493+
494+
library.DrawGetFontSize.argtypes = [ctypes.c_void_p]
495+
library.DrawGetFontSize.restype = ctypes.c_double
496+
497+
library.DrawGetTextAlignment.argtypes = [ctypes.c_void_p]
498+
library.DrawGetTextAlignment.restype = ctypes.c_int
499+
500+
library.DrawGetTextAntialias.argtypes = [ctypes.c_void_p]
501+
library.DrawGetTextAntialias.restype = ctypes.c_int
502+
503+
library.DrawGetTextDecoration.argtypes = [ctypes.c_void_p]
504+
library.DrawGetTextDecoration.restype = ctypes.c_int
505+
506+
library.DrawGetTextEncoding.argtypes = [ctypes.c_void_p]
507+
library.DrawGetTextEncoding.restype = ctypes.c_char_p
508+
509+
library.DrawGetTextInterlineSpacing.argtypes = [ctypes.c_void_p]
510+
library.DrawGetTextInterlineSpacing.restype = ctypes.c_double
511+
512+
library.DrawGetTextInterwordSpacing.argtypes = [ctypes.c_void_p]
513+
library.DrawGetTextInterwordSpacing.restype = ctypes.c_double
514+
515+
library.DrawGetTextKerning.argtypes = [ctypes.c_void_p]
516+
library.DrawGetTextKerning.restype = ctypes.c_double
517+
518+
library.DrawGetTextUnderColor.argtypes = [ctypes.c_void_p,
519+
ctypes.c_void_p]
520+
521+
library.DrawSetGravity.argtypes = [ctypes.c_void_p,
522+
ctypes.c_int]
523+
524+
library.DrawGetGravity.argtypes = [ctypes.c_void_p]
525+
library.DrawGetGravity.restype = ctypes.c_int
526+
527+
library.MagickAnnotateImage.argtypes = [ctypes.c_void_p,
528+
ctypes.c_void_p,
529+
ctypes.c_double,
530+
ctypes.c_double,
531+
ctypes.c_double,
532+
ctypes.c_char_p]
533+
library.MagickAnnotateImage.restype = ctypes.c_int
534+
535+
library.ClearDrawingWand.argtypes = [ctypes.c_void_p]
536+
537+
library.MagickDrawImage.argtypes = [ctypes.c_void_p,
538+
ctypes.c_void_p]
539+
library.MagickDrawImage.restype = ctypes.c_int
540+
541+
library.DrawLine.argtypes = [ctypes.c_void_p,
542+
ctypes.c_double,
543+
ctypes.c_double,
544+
ctypes.c_double,
545+
ctypes.c_double]
546+
547+
library.DrawAnnotation.argtypes = [ctypes.c_void_p,
548+
ctypes.c_double,
549+
ctypes.c_double,
550+
ctypes.POINTER(ctypes.c_ubyte)]
551+
552+
library.MagickQueryFontMetrics.argtypes = [ctypes.c_void_p,
553+
ctypes.c_void_p,
554+
ctypes.c_char_p]
555+
library.MagickQueryFontMetrics.restype = ctypes.POINTER(ctypes.c_double)
556+
557+
library.MagickQueryMultilineFontMetrics.argtypes = [ctypes.c_void_p,
558+
ctypes.c_void_p,
559+
ctypes.c_char_p]
560+
library.MagickQueryMultilineFontMetrics.restype = ctypes.POINTER(
561+
ctypes.c_double
562+
)
381563
except AttributeError:
382564
raise ImportError('MagickWand shared library not found or incompatible')
383565

0 commit comments

Comments
 (0)