Title: wp_constrain_dimensions
Published: December 18, 2014
Last modified: May 20, 2026

---

# apply_filters( ‘wp_constrain_dimensions’, int[] $dimensions, int $current_width, int $current_height, int $max_width, int $max_height )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/wp_constrain_dimensions/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/wp_constrain_dimensions/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp_constrain_dimensions/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp_constrain_dimensions/?output_format=md#changelog)

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

Filters dimensions to constrain down-sampled images to.

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

 `$dimensions`int[]

An array of width and height values.

 * `0` int
 * The width in pixels.
 * `1` int
 * The height in pixels.

`$current_width`int

The current width of the image.

`$current_height`int

The current height of the image.

`$max_width`int

The maximum width permitted.

`$max_height`int

The maximum height permitted.

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

    ```php
    return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
    ```

[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#L518)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/media.php#L518-L518)

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

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

Calculates the new dimensions for a down-sampled image.

  |

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

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

## User Contributed Notes

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