Hi Elliot,
Is there an easy way to get the width and height of each image in the gallery? Currently i’m using getimagesize() function, but sometime this function makes troubles. Something similar to how we pass the url: $image[‘url’], so it would be: $image[‘width’] and $image[‘height’]
This is the code i currently use:
$images = get_field( 'post_upload_gallery' );
if ( $images ):
foreach( $images as $image ):
$get_size = $image['sizes']['gallery-carousel'];
$size = getimagesize( $get_size );
echo '<img src="' . $image['url'] . '" width="' . $size[0] . '" height="' . $size[1] . '" />';
endforeach;
endif;
Hi @Vasili
The width and height attributes exist in the $image
variable.
Just dump out the value of $image
to see what is available!
<?php
echo '<pre>';
print_r($image);
echo '</pre>';
die;
?>