Support » Developing with WordPress » wp_get_additional_image_sizes retuning true if image is smaller

  • Resolved Percipero

    (@sudwebdesign)


    I’m confused with the functions wp_get_additional_image_sizes and has_image_size as they both return an array or true even if the fullsize image is smaller than this thumbsize.

    For example:
    I have an image which is 196x196px
    My results listing requires a thumb of 260x260px, so I call has_image_size for the custom listing_thumb-260 thumb size. It returns true.
    If you var_dump( wp_get_additional_image_sizes()[‘listing_thumb-260’]) it returns:
    array (size=3)
    ‘width’ => int 260
    ‘height’ => int 260
    ‘crop’ => boolean true
    But this isn’t true the image is only 196px.

Viewing 3 replies - 1 through 3 (of 3 total)
  • https://developer.wordpress.org/reference/functions/wp_get_additional_image_sizes/
    The wp_get_additional_image_sizes give you all the sizes. Your var_dump call shows the entry for the ‘listing_thumb-260’ size only.
    The has_image_size function simply returns whether the passed image size name is defined or not.

    Thank you for your reply!

    >The wp_get_additional_image_sizes give you all the sizes. Your var_dump call shows the entry for the ‘listing_thumb-260’ size only.

    Yes, I find the function names very misleading. I have found what I need to do is call wp_get_attachment_image_src( $att_id, ‘listing_thumb-260’ ) and then test the sizes returned in that array – there doesn’t seem to be any WP function to tell me if the thumb for that attachment id exists or not.

    resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_get_additional_image_sizes retuning true if image is smaller’ is closed to new replies.