Home Forums General Issues Check if image size exists


Check if image size exists

  • Does the image field return false if a certain image size doesn’t exist?

    For example, would the below return false if the image didn’t have the size of ‘hero-large’?

    $theImage = get_sub_field(‘hero_image’)[‘sizes’][‘hero-large’];

    I want to use that to check if the image exists. If not, then use a different size.

    if ($theImage) {
    //do nothing
    } else {
    $theImage = get_sub_field(‘hero_image’)[‘sizes’][‘hero-small’];

    Would that work?

  • If the image size does not exist, usually because the original image is smaller then the defined image field then the full size image is returned.

    When using wp_get_attachment_image_src() the return arrays 4th element will be true if the image at that size has been resized.

    I do not know if this information about the image is returned in the image size details.

    Find out

    $theImage = get_sub_field('hero_image');
    echo '<pre>'; print_r($theImage); echo '</pre>';
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.