Support

Account

Home Forums Add-ons Gallery Field Gallery images width and height attributes

Solved

Gallery images width and height attributes

  • 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;
    
     ?>
    
  • Hi Elliot

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Gallery images width and height attributes’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.