Home Forums General Issues Can\'t display Width or Height for Full sized image.


Can\'t display Width or Height for Full sized image.

  • I’m using this code to display an image, I need to use the Full image size and use display its width and height in my markup.

    If i set $size to thumbnail/medium/large the code returns the size values, but does not if $size is set to full.

    Can anyone explain/advise?

    $image = get_field('image_object');
    	$url = $image['url'];
    	$size = 'full';
    	$width = $image['sizes'][ $size . '-width' ];
    	$height = $image['sizes'][ $size . '-height' ];
    <img src="<?php echo $url; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"/>
  • Hi @muckleby

    The problem is that fullsize “width” and “height” does not exists in the array.

    // You will get the "full" size image with:
    $url = $image['url'];
    // Full-size Image Width:
    // Full-size Image Height:
    echo '<img src="'.$image['url'].'" width="'.$image['width'].'" height="'.$image['height'].'" />';
    // You can check all available values with:
    echo "<pre>";
    echo "</pre>";

    Hope i could help you.

  • awesome i hoped it would be as simple as this.
    big thanks rjantis!

    seems like the $image['width']; property should be mentioned in the documentation. perhaps i missed it, or maybe it seems elementary to a more experienced brain.

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

You must be logged in to reply to this topic.