Skip to content

Commit bc2e9f2

Browse files
committed
Preserve crop on image size
1 parent 2d929ba commit bc2e9f2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

inc/app_replacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static function possible_data_ignore_flags() {
221221
*
222222
* @return array Size mapping.
223223
*/
224-
protected static function size_to_crop() {
224+
public static function size_to_crop() {
225225
if ( ! empty( self::$size_to_crop ) ) {
226226
return self::$size_to_crop;
227227
}

inc/traits/normalizer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public function size_to_dimension( $size, $image_meta, $attachment_id = null ) {
206206
'height' => isset( $image_meta['height'] ) ? intval( $image_meta['height'] ) : false,
207207
];
208208
$image_args = Optml_App_Replacer::image_sizes();
209+
$sizes2crop = Optml_App_Replacer::size_to_crop();
209210
switch ( $size ) {
210211
case is_array( $size ):
211212
$width = isset( $size[0] ) ? (int) $size[0] : false;
@@ -226,6 +227,11 @@ public function size_to_dimension( $size, $image_meta, $attachment_id = null ) {
226227
}
227228

228229
list( $sizes['width'], $sizes['height'] ) = image_constrain_size_for_editor( $sizes['width'], $sizes['height'], $size );
230+
$resize = apply_filters( 'optml_default_crop', [] );
231+
if ( isset( $sizes2crop[ $sizes['width'] . $sizes['height'] ] ) ) {
232+
$resize = $this->to_optml_crop( $sizes2crop[ $sizes['width'] . $sizes['height'] ] );
233+
}
234+
$sizes['resize'] = $resize;
229235
self::$dimension_cache[ $cache_key ] = $sizes;
230236
break;
231237
case 'full' !== $size && isset( $image_args[ $size ] ):

0 commit comments

Comments
 (0)