@@ -19,18 +19,25 @@ class ImageUtility {
19
19
* @return array{'x': int, 'y': int, 'width': int, 'height': int}
20
20
*/
21
21
public static function getCrop (FileInterface $ image , string $ cropAreaName = 'default ' ): array {
22
+ $ width = $ image ->getProperty ('width ' );
23
+ $ height = $ image ->getProperty ('height ' );
24
+ assert (is_int ($ width ));
25
+ assert (is_int ($ height ));
26
+
22
27
$ emptyCrop = [
23
28
'x ' => 0 ,
24
29
'y ' => 0 ,
25
- 'width ' => ( int ) $ image -> getProperty ( ' width ' ) ,
26
- 'height ' => ( int ) $ image -> getProperty ( ' height ' ) ,
30
+ 'width ' => $ width ,
31
+ 'height ' => $ height ,
27
32
];
28
33
29
34
$ crop = $ image ->getProperty ('crop ' );
30
35
if (!$ crop ) {
31
36
return $ emptyCrop ;
32
37
}
33
38
39
+ assert (is_string ($ crop ));
40
+
34
41
$ cropVariantCollection = CropVariantCollection::create ($ crop );
35
42
$ cropArea = $ cropVariantCollection ->getCropArea ($ cropAreaName );
36
43
if ($ cropArea ->isEmpty ()) {
@@ -56,7 +63,13 @@ public static function convertCropForProcessing(FileInterface $image, ?array $cr
56
63
if ($ cropValues === null ) {
57
64
return null ;
58
65
}
59
- if ($ cropValues ['x ' ] === 0 && $ cropValues ['y ' ] === 0 && $ cropValues ['width ' ] === (int )$ image ->getProperty ('width ' ) && $ cropValues ['height ' ] === (int )$ image ->getProperty ('height ' )) {
66
+
67
+ $ width = $ image ->getProperty ('width ' );
68
+ $ height = $ image ->getProperty ('height ' );
69
+ assert (is_int ($ width ));
70
+ assert (is_int ($ height ));
71
+
72
+ if ($ cropValues ['x ' ] === 0 && $ cropValues ['y ' ] === 0 && $ cropValues ['width ' ] === $ width && $ cropValues ['height ' ] === $ height ) {
60
73
// If the crop is the full image, it's faster to use "no crop".
61
74
return null ;
62
75
}
@@ -99,6 +112,7 @@ public static function adjustSizeForCrop(array $size, array $crop): array {
99
112
public static function getHotspot (FileInterface $ image ): array {
100
113
$ hotspot = $ image ->getProperty ('hotspot ' );
101
114
if ($ hotspot ) {
115
+ assert (is_string ($ hotspot ));
102
116
$ hotspot = json_decode ($ hotspot , true );
103
117
}
104
118
0 commit comments