Skip to content

Commit 20dbf79

Browse files
committed
Issue #669 - Allow x/y coords with gravity parameters
1 parent fbebe67 commit 20dbf79

File tree

3 files changed

+126
-107
lines changed

3 files changed

+126
-107
lines changed

docs/changes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ Unreleased.
2424
- Fixed :meth:`Image.liquid_rescale() <wand.image.BaseImage.liquid_rescale>` behavior
2525
by switching default value of ``delta_x`` from ``0`` to ``1``. [:issue:`653`]
2626
- Fixed :meth:`Image.sparse_color() <wand.image.BaseImage.sparse_color>`'s ``colors`` argument structure to allow multiple (x, y) points with the same color value.
27+
- Fixed offset coordinates when used with ``gravity`` parameters. [:issue:`669`]
28+
29+
- :meth:`Image.chop() <wand.image.BaseImage.chop>`
30+
- :meth:`Image.composite() <wand.image.BaseImage.composite>`
31+
- :meth:`Image.composite_channel() <wand.image.BaseImage.composite_channel>`
32+
- :meth:`Image.crop() <wand.image.BaseImage.crop>`
33+
- :meth:`Image.extent() <wand.image.BaseImage.extent>`
34+
- :meth:`Image.region() <wand.image.BaseImage.region>`
35+
- :meth:`Image.splice() <wand.image.BaseImage.splice>`
36+
2737
- [TEST] Added Python 3.12 regression test. [:issue:`648` by Thijs Triemstra]
2838

2939

tests/image_methods_test.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ def test_chop_gravity():
250250
with Image(filename='rose:') as img:
251251
img.chop(width=10, height=10, gravity='south_east')
252252
assert (60, 36, 0, 0) == img.page
253-
with raises(ValueError):
254-
with Image(filename='rose:') as img:
255-
img.chop(x=10, gravity='north')
253+
with Image(filename='rose:') as img:
254+
img.chop(width=10, height=10, x=10, y=10, gravity='north')
255+
assert (60, 36, 0, 0) == img.page
256256

257257

258258
@mark.skipif(MAGICK_VERSION_NUMBER < 0x709,
@@ -660,14 +660,6 @@ def test_crop_gravity(fx_asset):
660660
assert southeast[mid_width, mid_height] == Color('transparent')
661661

662662

663-
def test_crop_gravity_error():
664-
with Image(filename='rose:') as img:
665-
with raises(TypeError):
666-
img.crop(gravity='center')
667-
with raises(ValueError):
668-
img.crop(width=1, height=1, gravity='nowhere')
669-
670-
671663
def test_crop_issue367():
672664
with Image(filename='rose:') as img:
673665
expected = img.size
@@ -679,6 +671,12 @@ def test_crop_issue367():
679671
assert actual.size == expected
680672

681673

674+
def test_crop_issue669():
675+
with Image(filename='rose:') as img:
676+
img.crop(width=50, height=25, left=10, gravity='south')
677+
assert 50, 25 == img.size
678+
679+
682680
def test_cycle_color_map(fx_asset):
683681
with Image(filename=str(fx_asset.joinpath('trim-color-test.png'))) as img:
684682
img.type = 'palette'
@@ -874,9 +872,9 @@ def test_extent_gravity():
874872
assert (10, 10, 0, 0) == img.page
875873
img.extent(width=100, height=100, gravity='center')
876874
assert (100, 100, 0, 0) == img.page
877-
with raises(ValueError):
878-
with Image(filename='rose:') as img:
879-
img.extent(x=10, gravity='north')
875+
with Image(filename='rose:') as img:
876+
img.extent(x=10, gravity='north')
877+
assert 70, 46 == img.size
880878

881879

882880
def test_features():
@@ -1730,10 +1728,10 @@ def test_region():
17301728
with src.region(width=10, height=10, gravity='south_east') as dst:
17311729
assert (70, 46, 60, 36) == dst.page
17321730
assert (10, 10) == dst.size
1733-
with raises(ValueError):
1734-
with Image(filename='rose:') as img:
1735-
with img.region(x=10, gravity='center') as _:
1736-
pass
1731+
with Image(filename='rose:') as img:
1732+
with img.region(x=10, gravity='center') as dst:
1733+
assert (70, 46, 10, 0) == dst.page
1734+
assert (60, 46) == dst.size
17371735

17381736

17391737
def test_remap():
@@ -2155,9 +2153,9 @@ def test_splice():
21552153
was = img.signature
21562154
img.splice(width=10, height=10, gravity='center')
21572155
assert img.signature != was
2158-
with raises(ValueError):
2159-
with Image(filename='rose:') as img:
2160-
img.splice(width=10, height=10, x=10, gravity='center')
2156+
with Image(filename='rose:') as img:
2157+
img.splice(width=10, height=10, x=10, gravity='center')
2158+
assert (80, 56) == img.size
21612159

21622160

21632161
def test_spread():

0 commit comments

Comments
 (0)