PHP: Getting image width and height from ID

Viewed 23

I'm trying to obtain image width and height from ID, but cannot see a way to do it.

getimagesize isn't an option as it requires a path/url.

A var_dump($image_atts) for my current attributes produces:

array(4) { [0]=> string(62) "http://test.test/wp-content/uploads/2022/08/icon-placeholder.svg" [1]=> int(0) [2]=> int(0) [3]=> bool(false) }

The above doesn't showcase any width or height properties.

Is there a way to get this data from ID?

Current approach:

if($image):
  $image_id = 218;
  $image_atts = wp_get_attachment_image_src( $image_id, 'full' );
  $image_src = $image_atts[0];
  $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
  // $image_info = getimagesize($image_id);
  // $image_width = $image_info[0];
  // $image_height = $image_info[1];
endif;

0 Answers
Related