Skip to content

Commit

Permalink
Merge pull request #283 from youknowone/caption-error
Browse files Browse the repository at this point in the history
`wand.image.Image.caption` raises TypeError with better description
  • Loading branch information
dahlia committed Mar 30, 2016
2 parents 4726601 + d004a70 commit ddb549f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/image_test.py
Expand Up @@ -1246,6 +1246,17 @@ def test_caption(fx_asset):
)


def test_caption_without_font(fx_asset):
with Image(width=144, height=192, background=Color('#1e50a2')) as img:
with raises(TypeError):
img.caption(
'Test message',
left=5, top=144,
width=134, height=20,
gravity='center'
)


def test_setfont(fx_asset):
with Image(width=144, height=192, background=Color('#1e50a2')) as img:
font = Font(
Expand Down
7 changes: 6 additions & 1 deletion wand/image.py
Expand Up @@ -916,9 +916,14 @@ def caption(self, text, left=0, top=0, width=None, height=None, font=None,
width = self.width - left
if height is None:
height = self.height - top
if not font:
try:
font = self.font
except TypeError:
raise TypeError('font must be specified or existing in image')
with Image() as textboard:
library.MagickSetSize(textboard.wand, width, height)
textboard.font = font or self.font
textboard.font = font
textboard.gravity = gravity or self.gravity
with Color('transparent') as background_color:
library.MagickSetBackgroundColor(textboard.wand,
Expand Down

0 comments on commit ddb549f

Please sign in to comment.