_wp_get_image_size_from_meta

Get the image size as array from its meta data.

Description

(array|bool) _wp_get_image_size_from_meta( (string) $size_name, (array) $image_meta ); 

Used for responsive images.

Returns (array|bool)

Array of width and height values in pixels (in that order) or false if the size doesn't exist.

Parameters (2)

0. $size_name (string)
Image size. Accepts any valid image size name ('thumbnail', medium,, etc.).
1. $image_meta (array)
The image meta data.

Usage

  1. if ( !function_exists( '_wp_get_image_size_from_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Image size. Accepts any valid image size name ('thumbnail', 'medium', etc.). 
  5. $size_name = ''; 
  6.  
  7. // The image meta data. 
  8. $image_meta = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _wp_get_image_size_from_meta($size_name, $image_meta); 
  12.  

Defined (1)

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

/wp-includes/media.php  
  1. function _wp_get_image_size_from_meta( $size_name, $image_meta ) { 
  2. if ( $size_name === 'full' ) { 
  3. return array( 
  4. absint( $image_meta['width'] ),  
  5. absint( $image_meta['height'] ),  
  6. ); 
  7. } elseif ( ! empty( $image_meta['sizes'][$size_name] ) ) { 
  8. return array( 
  9. absint( $image_meta['sizes'][$size_name]['width'] ),  
  10. absint( $image_meta['sizes'][$size_name]['height'] ),  
  11. ); 
  12.  
  13. return false;