Skip to content

Commit

Permalink
Merge 5cea4cf into 1c5f2a4
Browse files Browse the repository at this point in the history
  • Loading branch information
euphoris committed Apr 22, 2015
2 parents 1c5f2a4 + 5cea4cf commit 9f4befb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/image_test.py
Expand Up @@ -664,6 +664,27 @@ def test_crop_error(fx_asset):
img.crop(bottom=1, height=2)


def test_extent(fx_asset):
with Image(filename=str(fx_asset.join('croptest.png'))) as img:
with img.clone() as extended:
assert extended.size == img.size
extended.extent(width=500)
assert extended.width == 500
assert extended.height == img.height

with img.clone() as extended:
assert extended.size == img.size
extended.extent(height=500)
assert extended.width == img.width
assert extended.height == 500

with raises(ValueError):
img.extent(width=0)

with raises(ValueError):
img.extent(height=0)


@mark.parametrize(('method'), [
('resize'),
('sample'),
Expand Down
6 changes: 6 additions & 0 deletions wand/api.py
Expand Up @@ -498,6 +498,12 @@ class AffineMatrix(ctypes.Structure):
library.MagickTrimImage.argtypes = [ctypes.c_void_p,
ctypes.c_double]

library.MagickExtentImage.argtypes = [ctypes.c_void_p,
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_ssize_t,
ctypes.c_ssize_t]

library.MagickGaussianBlurImage.argtypes = [ctypes.c_void_p,
ctypes.c_double,
ctypes.c_double]
Expand Down
32 changes: 32 additions & 0 deletions wand/image.py
Expand Up @@ -1165,6 +1165,38 @@ def abs_(n, m, null=None):
if reset_coords:
self.reset_coords()

@manipulative
def extent(self, width=None, height=None, x=0, y=0):
"""extends the image as defined by the geometry, gravity, and wand
background color. Set the (x,y) offset of the geometry to move the
original wand relative to the extended wand.
:param width: the :attr:`width` of the extended image.
default is the :attr:`width` of the image.
:type width: :class:`numbers.Integral`
:param height: the :attr:`height` of the extended image.
default is the :attr:`height` of the image.
:type height: :class:`numbers.Integral`
:param x: the :attr:`x` offset of the extended image.
default is 0
:type x: :class:`numbers.Integral`
:param y: the :attr:`y` offset of the extended image.
default is 0
:type y: :class:`numbers.Integral`
"""
if width is None:
width = self.width
if height is None:
height = self.height
if width < 1:
raise ValueError('image width cannot be zero')
elif height < 1:
raise ValueError('image height cannot be zero')

result = library.MagickExtentImage(self.wand, width, height, x, y)
if not result:
self.raise_exception()

def reset_coords(self):
"""Reset the coordinate frame of the image so to the upper-left corner
is (0, 0) again (crop and rotate operations change it).
Expand Down

0 comments on commit 9f4befb

Please sign in to comment.