_wp_get_image_size_from_meta example

function wp_calculate_image_sizes( $size$image_src = null, $image_meta = null, $attachment_id = 0 ) {
    $width = 0;

    if ( is_array( $size ) ) {
        $width = absint( $size[0] );
    } elseif ( is_string( $size ) ) {
        if ( ! $image_meta && $attachment_id ) {
            $image_meta = wp_get_attachment_metadata( $attachment_id );
        }

        if ( is_array( $image_meta ) ) {
            $size_array = _wp_get_image_size_from_meta( $size$image_meta );
            if ( $size_array ) {
                $width = absint( $size_array[0] );
            }
        }
    }

    if ( ! $width ) {
        return false;
    }

    // Setup the default 'sizes' attribute.
if ( $instance['alt'] ) {
                $image_attributes['alt'] = $instance['alt'];
            }

            $size = $instance['size'];

            if ( 'custom' === $size || ! in_array( $sizearray_merge( get_intermediate_image_sizes(), array( 'full' ) ), true ) ) {
                $size  = array( $instance['width']$instance['height'] );
                $width = $instance['width'];
            } else {
                $caption_size = _wp_get_image_size_from_meta( $instance['size']wp_get_attachment_metadata( $attachment->ID ) );
                $width        = empty( $caption_size[0] ) ? 0 : $caption_size[0];
            }

            $image_attributes['class'] .= sprintf( ' attachment-%1$s size-%1$s', is_array( $size ) ? implode( 'x', $size ) : $size );

            $image = wp_get_attachment_image( $attachment->ID, $size, false, $image_attributes );

        } else {
            if ( empty( $instance['url'] ) ) {
                return;
            }

            
Home | Imprint | This part of the site doesn't use cookies.