Skip to content

Commit

Permalink
Fixed Image.background_color when image not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
emcconville committed Aug 7, 2021
1 parent 144f79c commit 2d737cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Unreleased.
- Added :meth:`Image.image_set() <wand.image.Image.image_set>` method.
- Added :meth:`Image.image_swap() <wand.image.Image.image_swap>` method.
- Fixed sub-image extraction on read. [:issue:`532`]
- Fixed :attr:`~wand.image.BaseImage.background_color` attribute when image was not read.
- [DOC] Completed :doc:`Distortion <./guide/distortion>` guide. [:issue:`534`]
- [DOC] Added :doc:`Morphology <./guide/morphology>` guide.

Expand Down
18 changes: 13 additions & 5 deletions wand/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,9 +1476,15 @@ def background_color(self):
.. versionadded:: 0.1.9
.. versionchanged:: 0.6.7
Allow property to be set before image read.
"""
pixel = library.NewPixelWand()
result = library.MagickGetImageBackgroundColor(self.wand, pixel)
if library.MagickGetNumberImages(self.wand):
result = library.MagickGetImageBackgroundColor(self.wand, pixel)
else:
pixel = library.MagickGetBackgroundColor(self.wand)
result = True
if not result: # pragma: no cover
self.raise_exception()
else:
Expand All @@ -1493,10 +1499,12 @@ def background_color(self, color):
color = Color(color)
assertions.assert_color(color=color)
with color:
result = library.MagickSetImageBackgroundColor(self.wand,
color.resource)
if not result: # pragma: no cover
self.raise_exception()
# Only set the image background if an image was loaded.
if library.MagickGetNumberImages(self.wand):
result = library.MagickSetImageBackgroundColor(self.wand,
color.resource)
if not result: # pragma: no cover
self.raise_exception()
# Also set the image stack.
result = library.MagickSetBackgroundColor(self.wand,
color.resource)
Expand Down

0 comments on commit 2d737cf

Please sign in to comment.