@@ -129,7 +129,7 @@ private function parse_image_regions(
129
129
) {
130
130
Debug \log ("Parsing image regions of $ source_image_path ... " );
131
131
132
- $ image_regions = $ this ->read_rectangle_cropping_metadata (
132
+ $ image_regions = $ this ->xmp -> read_rectangle_cropping_metadata (
133
133
$ source_image_path
134
134
);
135
135
Debug \log (
@@ -148,60 +148,6 @@ private function parse_image_regions(
148
148
];
149
149
}
150
150
151
- /**
152
- * Reads the rectangle cropping XMP Image Region metadata from a given
153
- * file. See
154
- * https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#image-region
155
- *
156
- * @param string $path Absolute path to the image.
157
- * @return array XMP Image Region metadata structured in a way that can
158
- * directly be used as WordPress metadata.
159
- */
160
- private function read_rectangle_cropping_metadata ($ path ) {
161
- $ wordpress_metadata = [];
162
-
163
- $ image_editor = $ this ->global_functions ->wp_get_image_editor ($ path );
164
- if ($ this ->global_functions ->is_wp_error ($ image_editor )) {
165
- Debug \log (
166
- 'Could not create image editor for reading image size of ' .
167
- $ path .
168
- ': ' .
169
- $ image_editor ->get_error_message ()
170
- );
171
- return $ wordpress_metadata ;
172
- }
173
-
174
- $ image_size = $ image_editor ->get_size ();
175
-
176
- $ regions = $ this ->xmp ->read_rectangle_cropping_metadata ($ path );
177
- Debug \log ('Found relevant image regions: ' . print_r ($ regions , true ));
178
-
179
- foreach ($ regions as $ region ) {
180
- $ wordpress_metadata_region = [
181
- 'id ' => $ region ->id ,
182
- 'names ' => $ region ->names ,
183
- 'shape ' => $ region ->rbShape ,
184
-
185
- // Can be 'relative' or 'pixel', see
186
- // https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#boundary-measuring-unit
187
- 'unit ' => $ region ->rbUnit ,
188
-
189
- // Useful when unit is 'pixel', see
190
- // https://github.com/Frameright/image-display-control-web-component/blob/main/image-display-control/docs/reference/attributes.md
191
- 'imageWidth ' => $ image_size ['width ' ],
192
- 'imageHeight ' => $ image_size ['height ' ],
193
-
194
- 'x ' => $ region ->rbXY ->rbX ,
195
- 'y ' => $ region ->rbXY ->rbY ,
196
- 'height ' => $ region ->rbH ,
197
- 'width ' => $ region ->rbW ,
198
- ];
199
- array_push ($ wordpress_metadata , $ wordpress_metadata_region );
200
- }
201
-
202
- return $ wordpress_metadata ;
203
- }
204
-
205
151
/**
206
152
* Mockable wrapper for calling global functions.
207
153
*
0 commit comments