• Resolved Anonymous User 14978628

    (@anonymized-14978628)


    Hi Stefan,

    I’m having some confusion regarding the selected image sizes which i’m hoping you can clarify for me please.

    My understanding is that by having different image sizes in the srcset, the browser will automatically choose the best size for the display device. So smaller image sizes for smaller screens, and larger sizes for larger screens.

    I have tried to apply this logic to my homepage images by adding sizes for phone, tablet and pc screens based on how the image sizes change responsively for each device (including landscape/portrait orientations). I used the chrome extension “window resizer beta” to determine what these image sizes are.

    This gives me the following sizes which i added to my functions.php

    add_image_size( 'Homepage-iPad-Portrait', 676, 480 );
    add_image_size( 'Homepage-iPad-Portrait@2x', 1352, 960 );
    add_image_size( 'Homepage-iPad-Landscape', 285, 203 );
    add_image_size( 'Homepage-iPad-Landscape@2x', 570, 406 );
    add_image_size( 'Homepage-iPhone6-Portrait', 322, 229 );
    add_image_size( 'Homepage-iPhone6-Portrait@2x', 644, 458 );
    add_image_size( 'Homepage-iPhone6-Landscape', 585, 415 );
    add_image_size( 'Homepage-iPhone6-Landscape@2x', 1170, 830 );
    add_image_size( 'Homepage-iPhone5-Portrait', 273, 194 );
    add_image_size( 'Homepage-iPhone5-Portrait@2x', 546, 388 );
    add_image_size( 'Homepage-iPhone5-Landscape', 496, 352 );
    add_image_size( 'Homepage-iPhone5-Landscape@2x', 992, 704 );
    add_image_size( 'et-builder-portfolio-image@2x', 800, 568 );

    And the code i used for the homepage images was the one you gave before but now including these sizes:

    <a href="<?php echo get_permalink( $post->ID );?>">
                <?php
                $thumbnail_id = get_post_thumbnail_id( $post->ID );
                echo rwp_img( $thumbnail_id, array (
                    'sizes' => array( 'et-builder-portfolio-image@2x', 'Homepage-iPad-Portrait', 'Homepage-iPad-Portrait@2x', 'Homepage-iPad-Landscape', 'Homepage-iPad-Landscape@2x', 'Homepage-iPhone6-Portrait', 'Homepage-iPhone6-Portrait@2x', 'Homepage-iPhone6-Landscape', 'Homepage-iPhone6-Landscape@2x', 'Homepage-iPhone5-Portrait', 'Homepage-iPhone5-Portrait@2x', 'Homepage-iPhone5-Landscape', 'Homepage-iPhone5-Landscape@2x' ),
                ) );
                ?>
                </a>

    The problem i’m having is that when i run Google PageSpeed Insights, it tells me my images need to be optimized. Specifically the larger sized images and retina images.

    I’m confused as to why this is happening as i thought the whole point of having srcset was to be able to display different sized images to different sized screens. So i thought by doing what i’ve done my images would be optimized, but for some reason Google is saying they are not? I have the retina option enabled in Responsify Wp.

    Am i missing something obvious here?

    https://ww.wp.xz.cn/plugins/responsify-wp/

Viewing 76 replies (of 76 total)
  • Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    But since Lazy Load XT works, except for retina

    Sorry i should have been more specific. What works is lazy load with the a3 plugin activated. With the lazy load xt plugin both the rwp_img and rwp_attributes code output a larger natural image than specified in the media query.

    For example,

    <a href="<?php echo get_permalink( $post->ID );?>">
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $attributes = rwp_attributes( $thumbnail_id, array(
        'element' => 'img',
        'sizes' => array('Homepage', 'Homepage2' )
    ));
    echo '<img data-srcset="'.$attributes['srcset'].'" sizes="(min-width: 981px) 402px, (min-width: 480px) 691px, 402px">';
    ?>
        </a>

    Gives me 402×271 (natural 691×466) when viewed as desktop, so the natural image should be 402px wide not 691.

    If i add retina images to the array as follows:

    <a href="<?php echo get_permalink( $post->ID );?>">
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $attributes = rwp_attributes( $thumbnail_id, array(
        'element' => 'img',
        'sizes' => array('Homepage', 'Homepage@2x', 'Homepage2', 'Homepage2@2x' )
    ));
    echo '<img data-srcset="'.$attributes['srcset'].'" sizes="(min-width: 981px) 402px, (min-width: 480px) 691px, 402px">';
    ?>
        </a>

    I get 402×271 (natural 1382×932) when viewed as desktop. So it is using the retina version of the 691×466 image, which should only be displayed for smaller devices (min-width: 480px) 691px.

    I get the exact same results when using rwp_img

    <a href="<?php echo get_permalink( $post->ID );?>">
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array(
        'sizes' => array('Homepage', 'Homepage@2x', 'Homepage2', 'Homepage2@2x' ),
        'attributes' => array(
            'sizes' => '(min-width: 981px) 402px, (min-width: 480px) 691px, 402px'
        )
    ));
    ?>
    </a>

    I have explained the details just for your own interest because i don’t think this is an issue with the plugin but rather the lazy load xt script having some kind of incompatibility with your plugin. The reason i say this is because the a3 lazy load plugin outputs the correct image sizes for all my media queries. So it works properly, but for some reason xt does not.

    except for retina, I think you should ask yourself if it’s really that important? As I’ve said before, it’s on logos and symbols that you really can tell the difference. If a photo is retina or not isn’t that obvious.

    Yeah, i remember you saying this so thought i would put it to the test. Since i don’t have a retina display, i used a half resolution image in place of a larger resolution image. For example, a 400×400 image where a 800×800 image would normally be. This resulted in the image looking noticeably blurry. Was this a fair test of what non retina images would look like on a retina display?

    My thinking is that high dpi displays are the future and it’s only a matter of time before they become commonplace so it’s best to futureproof myself now. Who knows, in a few years i could be asking you how to get RWP working with holographic displays? 😛 😉

    I think you should ask yourself if lazy loading is this important to. It makes sense on pages with many images

    I do plan to use images throughout posts so lazy loading would be a benefit. Again, it helps to futureproof by increasing speed so it’s something i would definitely like to use. I’d prefer to embrace new technologies wherever possible.

    Fortunately a3 lazy load is working well, and my issue of slow lazy loading post images miraculously seemed to fix itself after testing all those other plugins last night. So i’m happy with that.

    I think we should close this thread soon, we are very far away from the original question

    True! I forgot what my original question was! lol Thanks for your patience!

Viewing 76 replies (of 76 total)

The topic ‘Selecting Image Size’ is closed to new replies.