Title: image_resize_dimensions
Published: April 25, 2014
Last modified: May 20, 2026

---

# apply_filters( ‘image_resize_dimensions’, null|mixed $null, int $orig_w, int $orig_h, int $dest_w, int $dest_h, bool|array $crop )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#wp--skip-link--target)

Filters whether to preempt calculating the image resize dimensions.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#description)󠁿

Returning a non-null value from the filter will effectively short-circuit [image_resize_dimensions()](https://developer.wordpress.org/reference/functions/image_resize_dimensions/),
returning that value instead.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#parameters)󠁿

 `$null`null|mixed

Whether to preempt output of the resize dimensions.

`$orig_w`int

Original width in pixels.

`$orig_h`int

Original height in pixels.

`$dest_w`int

New width in pixels.

`$dest_h`int

New height in pixels.

`$crop`bool|array

Whether to crop image to specified width and height or resize.
 An array can specify
positioning of the crop area. Default false.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#more-information)󠁿

 * Since version [3.4](https://wordpress.org/support/wordpress-version/version-3-4/),
   the `image_resize_dimensions` filter is used to filter the thumbnail and alternative
   sizes dimensions of image assets during resizing operations. This enables the
   override of WordPress default behavior on image resizing, including the thumbnail
   cropping.
 * Note that the filter function **must** return an array matching the parameters
   to `imagecopyresampled()`, **or** `false` if the resizing is impossible, **or**
   should not occur, **or** `null` to fallback to WordPress default behavior.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#source)󠁿

    ```php
    $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/media.php#L569)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/media.php#L569-L569)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#related)󠁿

| Used by | Description | 
| [image_resize_dimensions()](https://developer.wordpress.org/reference/functions/image_resize_dimensions/)`wp-includes/media.php` |

Retrieves calculated resize dimensions for use in [WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/).

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/?output_format=md#comment-content-4721)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/image_resize_dimensions/#comment-4721)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimage_resize_dimensions%2F%23comment-4721)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimage_resize_dimensions%2F%23comment-4721)
 4. Example migrated from Codex:
 5. This example filters the image resizing dimensions to force WordPress to crop thumbnails
    by keeping the top of the image, instead of the default center.
 6.     ```php
        add_filter( 'image_resize_dimensions', 'custom_image_resize_dimensions', 10, 6 );
    
        function custom_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop ){
    
        	// Change this to a conditional that decides whether you 
        	// want to override the defaults for this image or not.
        	if( false )
        		return $payload;
    
        	if ( $crop ) {
        		// crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        		$aspect_ratio = $orig_w / $orig_h;
        		$new_w = min($dest_w, $orig_w);
        		$new_h = min($dest_h, $orig_h);
    
        		if ( !$new_w ) {
        			$new_w = intval($new_h * $aspect_ratio);
        		}
    
        		if ( !$new_h ) {
        			$new_h = intval($new_w / $aspect_ratio);
        		}
    
        		$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
    
        		$crop_w = round($new_w / $size_ratio);
        		$crop_h = round($new_h / $size_ratio);
    
        		$s_x = floor( ($orig_w - $crop_w) / 2 );
        		$s_y = 0; // [[ formerly ]] ==> floor( ($orig_h - $crop_h) / 2 );
        	} else {
        		// don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        		$crop_w = $orig_w;
        		$crop_h = $orig_h;
    
        		$s_x = 0;
        		$s_y = 0;
    
        		list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
        	}
    
        	// if the resulting image would be the same size or larger we don't want to resize it
        	if ( $new_w >= $orig_w && $new_h >= $orig_h )
        		return false;
    
        	// the return array matches the parameters to imagecopyresampled()
        	// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
        	return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
    
        }
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimage_resize_dimensions%2F%3Freplytocom%3D4721%23feedback-editor-4721)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimage_resize_dimensions%2F)
before being able to contribute a note or feedback.