Skip to content

Commit 78712d5

Browse files
authored
Allow >1 gravity coordinates per imgproxy docs (#7)
1 parent 31b29e0 commit 78712d5

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

src/Options/Gravity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function __construct(string $type, ?float $x = null, ?float $y = null)
2222
{
2323
$this->type = new GravityType($type);
2424

25-
if ($x < 0 || $x > 1) {
25+
if ($x < 0) {
2626
throw new InvalidArgumentException(sprintf('Invalid gravity X: %s', $x));
2727
}
2828

29-
if ($y < 0 || $y > 1) {
29+
if ($y < 0) {
3030
throw new InvalidArgumentException(sprintf('Invalid gravity Y: %s', $y));
3131
}
3232

tests/Options/CropTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function validData(): array
6262
[100, 0, 'ce', 'c:100:0:ce'],
6363
[100, 200, 'ce', 'c:100:200:ce'],
6464
[100, 200, 'ce:0:0', 'c:100:200:ce:0:0'],
65+
[100, 200, 'ce:200:250', 'c:100:200:ce:200:250'],
6566
];
6667
}
6768

@@ -85,8 +86,8 @@ public function invalidGravityData(): array
8586
['foo', 'Invalid gravity: foo'],
8687
['ce:bar:0', 'Gravity X should be numeric'],
8788
['ce:0:baz', 'Gravity Y should be numeric'],
88-
['ce:100:0', 'Invalid gravity X: 100'],
89-
['ce:0:500', 'Invalid gravity Y: 500'],
89+
['ce:-100:0', 'Invalid gravity X: -100'],
90+
['ce:0:-500', 'Invalid gravity Y: -500'],
9091
];
9192
}
9293
}

tests/Options/ExtendAspectRatioTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function exampleData(): array
4444
[false, null, 'exar:0'],
4545
[true, 'ce', 'exar:1:ce'],
4646
[false, 'ce:0:0', 'exar:0:ce:0:0'],
47+
[false, 'ce:200:250', 'exar:0:ce:200:250'],
4748
];
4849
}
4950

@@ -56,8 +57,8 @@ public function invalidGravityData(): array
5657
['foo', 'Invalid gravity: foo'],
5758
['ce:bar:0', 'Gravity X should be numeric'],
5859
['ce:0:baz', 'Gravity Y should be numeric'],
59-
['ce:100:0', 'Invalid gravity X: 100'],
60-
['ce:0:500', 'Invalid gravity Y: 500'],
60+
['ce:-100:0', 'Invalid gravity X: -100'],
61+
['ce:0:-500', 'Invalid gravity Y: -500'],
6162
];
6263
}
6364
}

tests/Options/ExtendTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function exampleData(): array
4646
[false, null, 'ex:0'],
4747
[true, 'ce', 'ex:1:ce'],
4848
[false, 'ce:0:0', 'ex:0:ce:0:0'],
49+
[false, 'ce:200:250', 'ex:0:ce:200:250'],
4950
];
5051
}
5152

@@ -58,8 +59,8 @@ public function invalidGravityData(): array
5859
['foo', 'Invalid gravity: foo'],
5960
['ce:bar:0', 'Gravity X should be numeric'],
6061
['ce:0:baz', 'Gravity Y should be numeric'],
61-
['ce:100:0', 'Invalid gravity X: 100'],
62-
['ce:0:500', 'Invalid gravity Y: 500'],
62+
['ce:-100:0', 'Invalid gravity X: -100'],
63+
['ce:0:-500', 'Invalid gravity Y: -500'],
6364
];
6465
}
6566
}

tests/Options/GravityTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function validData(): array
8686
['fp', 0.5, null, 'g:fp:0.5'],
8787
['fp', null, 0.5, 'g:fp::0.5'],
8888
['fp', 0.5, 0.7, 'g:fp:0.5:0.7'],
89+
['fp', 200, 250, 'g:fp:200:250'],
8990
];
9091
}
9192

@@ -99,6 +100,7 @@ public function validDataFromString(): array
99100
['ce:0.5', 'g:ce:0.5'],
100101
['ce:0:0', 'g:ce:0:0'],
101102
['ce:0.1:0.5', 'g:ce:0.1:0.5'],
103+
['ce:200:250', 'g:ce:200:250'],
102104
];
103105
}
104106

@@ -131,6 +133,7 @@ public function invalidGravityType(): array
131133
public function invalidGravityOffset(): array
132134
{
133135
return [
136+
[-100],
134137
[-1],
135138
[-1.01],
136139
];

0 commit comments

Comments
 (0)