wp_expand_dimensions

Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height.

Description

(array) wp_expand_dimensions( (int) $example_width, (int) $example_height, (int) $max_width, (int) $max_height ); 

Returns (array)

The maximum possible width and height based on the example ratio.

Parameters (4)

0. $example_width (int)
The width of an example embed.
1. $example_height (int)
The height of an example embed.
2. $max_width (int)
The maximum allowed width.
3. $max_height (int)
The maximum allowed height.

Usage

  1. if ( !function_exists( 'wp_expand_dimensions' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // The width of an example embed. 
  5. $example_width = -1; 
  6.  
  7. // The height of an example embed. 
  8. $example_height = -1; 
  9.  
  10. // The maximum allowed width. 
  11. $max_width = -1; 
  12.  
  13. // The maximum allowed height. 
  14. $max_height = -1; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wp_expand_dimensions($example_width, $example_height, $max_width, $max_height); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/media.php  
  1. function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) { 
  2. $example_width = (int) $example_width; 
  3. $example_height = (int) $example_height; 
  4. $max_width = (int) $max_width; 
  5. $max_height = (int) $max_height; 
  6.  
  7. return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );